Different results coming out of an init method than those expected. Why does this happen and how can
Posted
by Mark Reid
on Stack Overflow
See other posts from Stack Overflow
or by Mark Reid
Published on 2010-05-18T12:57:29Z
Indexed on
2010/05/18
13:00 UTC
Read the original article
Hit count: 258
objective-c
|objective-c-2.0
When I run this method the two properties I have are set to (NULL) when I try and access them outside of the if statement. But they are set to 0 and NO if I check them inside the for loop.
-(id) init
{
NSLog(@"Jumping into the init method!");
if (self = [super init]) {
NSLog(@"Running the init method extras");
accumulator = 0;
NSLog(@"self.accumulator is %g", accumulator);
decimal = NO;
}
NSLog(@"Calc after init is: %@ and %@", self.accumulator, self.decimal);
return self;
}
Any suggestions as to why what comes out is different from what's done in the for loop?
© Stack Overflow or respective owner