使用 [[NSUserDefaults standardUserDefaults] setBool:(BOOL)value forKey:(NSString *)defaultName]
设置的值,如果用普通的objectForKey:
取出的值是__NSCFBoolean
类型,if
语句无法判断,即使后加== YES
也没用,还会出问题。
要用 [[NSUserDefaults standardUserDefaults] boolForKey:(NSString *)defaultName]
来取值,
同理:
1 2 3 4 5
| - (void)setInteger:(NSInteger)value forKey:(NSString *)defaultName; - (void)setFloat:(float)value forKey:(NSString *)defaultName; - (void)setDouble:(double)value forKey:(NSString *)defaultName; - (void)setBool:(BOOL)value forKey:(NSString *)defaultName; - (void)setURL:(nullable NSURL *)url forKey:(NSString *)defaultName;
|
如上所示等入值方法,都用对应配套的取值方法
1 2 3 4 5
| - (NSInteger)integerForKey:(NSString *)defaultName; - (float)floatForKey:(NSString *)defaultName; - (double)doubleForKey:(NSString *)defaultName; - (BOOL)boolForKey:(NSString *)defaultName; - (nullable NSURL *)URLForKey:(NSString *)defaultName;
|