lab12
lab12

Reputation: 6448

NSUserDefault exists -iPHONE SDK

How would I check in a "if" statement if the NSUserDefault object is saved there or not? I'm not really sure how to call it.. So a pretty short question..

Thanks

Upvotes: 1

Views: 1057

Answers (2)

Abizern
Abizern

Reputation: 150755

Dave's answer is correct, but I'd skip the explicit test for nil:

if ([[NSUserDefaults standardUserDefaults] objectForKey:@"Foo"]) {
    NSLog(@"An object is saved under \"Foo\"!");
}

Upvotes: 4

Dave DeLong
Dave DeLong

Reputation: 243156

if ([[NSUserDefaults standardUserDefaults] objectForKey:@"Foo"] != nil) {
  NSLog(@"an object is saved under \"Foo\"!");
}

Upvotes: 7

Related Questions