use*_*949 4 iphone cocoa-touch objective-c plist
我想为plist文件条目分配一个布尔值.我正在做以下事情:
NSString *aBool = realBoolValue ? @"YES" : @"NO";
[myplist setValue: aBool forKey:@"boolKey"];
[myplist writeToFile: [NSHomeDirectory() stringByAppendingPathComponent: plistFilePath] atomically:NO];
Run Code Online (Sandbox Code Playgroud)
但任务永远不会.我正在做以上操作,因为以下内容不起作用:
[myplist setValue: realBoolValue forKey:@"boolKey"];
Run Code Online (Sandbox Code Playgroud)
它给出了不兼容的类型错误.我究竟做错了什么?
- 编辑---
plistFilePath初始化为
plistFilePath = [NSHomeDirectory() stringByAppendingPathComponent: @"Library/Preferences/myfile.plist"];
Run Code Online (Sandbox Code Playgroud)
Tho*_*ing 16
您可以将其包装在NSNumber对象中:
[NSNumber numberWithBool:yourBool]
Run Code Online (Sandbox Code Playgroud)
从plist中读回值时使用[NSNumber boolValue].
| 归档时间: |
|
| 查看次数: |
5245 次 |
| 最近记录: |