开发者

Different results coming out of an init method than those expected. Why does this happen and how can I correct it?

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 if statement.

-(id) init  
{  
    NSLog(@"Jumping into the init method!");  

    if (self = [super init]) {  
        NSLog(@"Running the init met开发者_如何转开发hod 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?


The format specifiers are different: you're formatting as %@ (object) in the second case, %g (number) in the first.

(It's just as well they're zero anyway. Otherwise the %@s would probably crash.)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜