Reputation: 189
How can I compare settings.bundle toggle switch value correctly? Toggle switch is named enableAnotherUser.
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults synchronize];
if([defaults objectForKey:@"enableAnotherUser"]==1) // here i tried from 1, 0, nil, null, isEqual,... and none seem to work correctly?
{}
else
{}
po in console for [defaults objectForKey:@"enableAnotherUser"] returns 1.. but ==1 in if doesn't seem to matter, the program always goes to else part. Plus this warning on comparing 1, but not on 0: comparison between pointer and integer.
What should I do?
Upvotes: 1
Views: 1243
Reputation: 360
@kikovi - try something like this...
BOOL enableAnotherUser = [[NSUserDefaults standardUserDefaults] boolForKey:@"enableAnotherUser"];
if(enableAnotherUser) {
...
}
else {
...
}
Upvotes: 3