NSUserDefaults - How to tell if a key exists

前端 未结 11 1813
耶瑟儿~
耶瑟儿~ 2020-12-12 11:06

I\'m working on a small iPhone app, and I am using NSUserDefaults as my data persistence. It only has to keep track of a few things, such as some names and som

11条回答
  •  春和景丽
    2020-12-12 11:56

    The objectForKey: method will return nil if the value does not exist. Here's a simple IF / THEN test that will tell you if the value is nil:

    if([[NSUserDefaults standardUserDefaults] objectForKey:@"YOUR_KEY"] != nil) {
        ...
    }
    

提交回复
热议问题