Reputation: 2910
I'm setting a value in the user defaults and I don't know why it crashes:
[[NSUserDefaults standardUserDefaults] setObject:[textField text] forKey:@"STRING"];
This is fine but
[[NSUserDefaults standardUserDefaults] setObject:[textField text] forKey:settingKey];
This is not. settingKey
is the property declared and synthesized in the class I'm using in. In fact, even this line works
[textField setText:[[NSUserDefaults standardUserDefaults] objectForKey:settingKey]];
When simulator crashes it brings me to the Core Foundation Hash (CFHash) which I can't understand:
0x1c24756: call 0x1d79a00; symbol stub for: getpid
"Thread 1: EXC_BREAKPOINT (code=EXC_1386_BPT, subcode=0x0)"
Upvotes: 2
Views: 1970
Reputation: 8608
I'm not sure exactly what type of object your key is, so the crash could be caused by one of two issues:
settingKey
is not an object which can be stored in an NSDictionary. Any keys and their values stored in NSUserDefaults must be an NSString, NSInteger, etc. It cannot be a primitive data type like int or BOOL. More specifically, a key must be an NSString.settingKey
is NULL, has not been allocated, or has been deallocated prematurely then NSUserDefaults will cause a crash. Keys cannot be NULL in NSUserDefaults (or NSDictionaries)Upvotes: 0
Reputation: 8460
here problem is settingKey is null
value.
if you are trying to set null value as an key arguement then it'l happend.
Upvotes: 3