hit counter

Timeline

My development logbook

Timezones in Objective-c

To find out all timezone abbreviation,

1
2
3
4
5
6
    NSEnumerator *keys = [[NSTimeZone abbreviationDictionary] keyEnumerator];
    NSString* value;
    while ((value = [keys nextObject])) {
        NSLog(@"%@ %@", value, [[NSTimeZone abbreviationDictionary] objectForKey:value] );
    }

Here is the output:

EDT America/New_York
GMT GMT
AST America/Halifax
IRST Asia/Tehran
ICT Asia/Bangkok
PET America/Lima
KST Asia/Seoul
PST America/Los_Angeles
CDT America/Chicago
EEST Europe/Istanbul
NZDT Pacific/Auckland
WEST Europe/Lisbon
EAT Africa/Addis_Ababa
HKT Asia/Hong_Kong
IST Asia/Calcutta
MDT America/Denver
NZST Pacific/Auckland
WIT Asia/Jakarta
ADT America/Halifax
BST Europe/London
ART America/Argentina/Buenos_Aires
CAT Africa/Harare
GST Asia/Dubai
PDT America/Los_Angeles
SGT Asia/Singapore
COT America/Bogota
PKT Asia/Karachi
EET Europe/Istanbul
UTC UTC
WAT Africa/Lagos
EST America/New_York
JST Asia/Tokyo
CLST America/Santiago
CET Europe/Paris
BDT Asia/Dhaka
MSK Europe/Moscow
AKDT America/Juneau
CLT America/Santiago
AKST America/Juneau
BRST America/Sao_Paulo
BRT America/Sao_Paulo
CEST Europe/Paris
CST America/Chicago
HST Pacific/Honolulu
MSD Europe/Moscow
MST America/Denver
PHT Asia/Manila
WET Europe/Lisbon

Chastised by a CoreFoundation Class

This is an error message of a runtime exception thrown by NSCalendar:

I mean really, what do you think that operation is supposed to mean with a nil date?
An exception has been avoided for now.
A few of these errors are going to be reported with this complaint, then further violations will simply silently do whatever random thing results from the nil.
Here is the backtrace where this occurred this time (some frames may be missing due to compiler optimizations):

Hurts my newbie objective-c dev ego a bit :–)

Missing the viewDidLoad Event

This is my original code. It does the job and put a specialised view into a cell of a UICollectionView

1
2
3
4
5
    TT2TimeViewController* controller = [[TT2TimeViewController alloc] init];
    controller.city = city;
    UIView* view = [[[NSBundle mainBundle] loadNibNamed:@"TT2TimeViewController"
                                                  owner:controller
                                                options:nil] objectAtIndex:0];

However, for some reason, the view controller controller will miss the ViewDidLoad event. The selector is not called at all.

This problem is resolved if I switch to use initWithNibName instead:

1
2
    TT2TimeViewController* controller = [[TT2TimeViewController alloc] initWithNibName:@"TT2TimeViewController"
                                            bundle:[NSBundle mainBundle]];

Dispatch_once

Wanted to declare and initialise a static variable in a .m file.

Objective-c compiler does not like it, and raise this error message:

Initializer element is not a compile-time constant

I like the explanation here on Stackoverflow:

Objective-C is a strict superset of C. It’s illegal in C to have any executable code outside of a function (or method in Objective-C).

Leading from this answer I discovered that I should use dispatch_once for initialisation

scrollViewDidScroll Is Not Called

if - (void)scrollViewDidScroll:(UIScrollView *)scrollView of the delegate is not called, one should check:

  • Has the delegate of the ScrollView been assigned?

  • Have you set the contentSize? Is it bigger than the bounds of the ScrollView?

  • Is Autolayout on (if you use storyboard)?