开发者

NSUserDefault exists -iPHONE SDK

开发者 https://www.devze.com 2022-12-21 06:31 出处:网络
How would I check in a \"if\" statement if the NSUserDefault object i开发者_如何学Cs saved there or not? I\'m not really sure how to call it.. So a pretty short question..

How would I check in a "if" statement if the NSUserDefault object i开发者_如何学Cs saved there or not? I'm not really sure how to call it.. So a pretty short question..

Thanks


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


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\"!");
}
0

精彩评论

暂无评论...
验证码 换一张
取 消