NSUserDefaults: detecting nil
Posted
by
alJaree
on Stack Overflow
See other posts from Stack Overflow
or by alJaree
Published on 2011-01-09T16:19:41Z
Indexed on
2011/01/09
16:53 UTC
Read the original article
Hit count: 244
iphone
|nsuserdefaults
I have some code in my classes to read from NSUserDefaults
NSUserDefaults *defs = [NSUserDefaults standardUserDefaults];
score = [defs integerForKey:@"score"];
this causes a crash.
Im guessing it is because the score value is nil or doesnt exist.
How can I check if it is nil?
EDIT.
The following code causes a crash when storing to NSUserDefaults.
NSUserDefaults *defs = [NSUserDefaults standardUserDefaults];
[defs setInteger:0 forKey:@"score"];
[defs setInteger:3 forKey:@"lives"];
[defs release];
Im not sure what the issue is
On some crashes there isnt even a crash report in the console.
Thanks
© Stack Overflow or respective owner