NSCalendar


#1

Hi all…

Im trying to understand why this builds and runs ok:

While this builds OK but fails on running. (Xcode complains about BAD_ACCESS or something like that.)

NSCalendar *myCalendar; myCalendar = [NSCalendar alloc]; myCalendar = [myCalendar initWithCalendarIdentifier:NSGregorianCalendar];

Is it not the same principle as

[code]NSDate *myDate;
myDate = [NSDate alloc];
myDate = [myDate init];

// the same as:

NSDate *myDate = [[NSDate alloc] init];
[/code]
Which compiles and runs just the same.

What am i missing here ?

Regards
Dennis


#2

This may have something to do with ARC.

Turn it off and try again to see what you get.


#3

[quote=“ibex10”]This may have something to do with ARC.

Turn it off and try again to see what you get.[/quote]

Thanks, yes with ARC off there is no problem.
But is it valid code ? Did i loose the reference to the object since Xcode complains ?
Shouldn’t it work with ARC on ?

Should i generally leave ARC off ?

Regards
Dennis


#4

Just leave the settings as they are, but follow the conventions when creating objects.

That is, do this:

...
FooBar *fooBar = [[FooBar alloc] init];
...

Not this:

...
FooBar *fooBar = [FooBar alloc];
fooBar = [fooBar init];             // <-- This spells trouble with ARC on!
...

#5

Thanks, will do…

Dennis

[quote=“ibex10”]Just leave the settings as they are, but follow the conventions when creating objects.
[/quote]