I’ve bought a nice book of yours - Objective C (in german) and i’m trying now to do some Obj-C stuff. And i’m stuck on the 13th chapter. I’ve solved the challenge, but i have no idea, why does it work this way and not the other. Here is what i’m trying to say (well, my english is pretty bad - i’m sorry for that )
NSTimeZone *tZone2 = [NSTimeZone systemTimeZone]; NSLog(@"Now we have:"); if ([tZone2 isDaylightSavingTime] == YES) NSLog(@"summertime!"); else NSLog(@"wintertime!");
This one works perfectly. But my first attempts were something like this:
NSTimeZone *tzone = [[NSTimeZone alloc]init]; NSLog... if.. and so on
Because i’ve seen those “alloc init” bits everywhere.
As soon as I understand, this alloc init means “allocate some memory and initialize this new object”. And so i decided to put it on every new object or whatever It didn’t work. The pointer “tzone” returns NULL. So if i would like to log the name of the zone with [tzone name], it would write (null). I think, i should somehow “say” to use “systemTimeZone” method or property, or whatever on the initialization?
But my most important question is - in which cases do i have to use “alloc init” and in which not?
P.S. I’m very sorry for my english
Hey SORRY guys! I’ve found everything few threads ahead
So to manage my problem i had to write something like:
NSTimeZone *tzone = [[NSTimeZone alloc]init]; tzone = [NSTimeZone systemTimeZone];