5 ms·
Also for what its worth, variable declarations are not nil by default, this bug tied me up for quite some time. NSString *val; if(something){ val = @"he
by seanalltogether 14y ago
Also for what its worth, variable declarations are not nil by default, this bug tied me up for quite some time.
NSString *val;
if(something){
val = @"hello";
}else if(somthingelse){
val = @"goodbye";
}
if(val){
[self display:val];
}
this can send you on a wild goose chase for not declaring val = nil initially.
- mikeash 14y agoThis is no longer true when using ARC.
- Scorponok 14y agoThis is no longer true when using ARC. See the "Stack Variables Are Initialized with nil" section of http://developer.apple.com/library/ios/#releasenotes/ObjectiveC/RN-TransitioningToARC/Introduction/Introduction.html http://developer.apple.com/library/ios/#releasenotes/Objecti... "Using ARC, strong, weak, and autoreleasing stack variables are now implicitly initialized with nil." This doesn't affect plain C variables, but it would solve the issue you had above.
- micampe 14y agoAnd, if you don’t or can’t use ARC, turn on -Wuninitialized or use the static analyzer (clang warns on uninitialized values only with -Wall).
- xsmasher 14y agoThat's a rule of C; stack vars are not initialized. Same thing would happen with an int. Member variables of a class are set to zero by (init or alloc? can't remember.)