K2D*_*tal 16 iphone objective-c
我正在尝试为我的iPhone应用程序实现保存状态.
我有一个名为SaveData.plist的plist文件,我可以通过以下方式读取它
NSString *pListPath2 = [bundle pathForResource:@"SaveData" ofType:@"plist"];
NSDictionary *dictionary2 = [[NSDictionary alloc] initWithContentsOfFile:pListPath2];
self.SaveData = dictionary2;
[dictionary release];
Run Code Online (Sandbox Code Playgroud)
Plist文件有成员
SavedGame这是一个布尔值,告诉应用程序这里是否确实存在有效数据(如果他们没有在游戏中退出应用程序,我不希望他们成为还原点.
分数是NSNumber.时间是一个NSNumber
Playfield是一个16个元素的NSNumber数组
如何访问NSDictionary中的这些元素?
Jef*_*man 26
尝试 [NSDictionary objectForKey:]
其中Key是plist中成员的名称.
例如:
BOOL save = [[dictionary2 objectForKey:@"SavedGame"] boolValue];
Run Code Online (Sandbox Code Playgroud)
将存储在plist中的对象存储为SavedGame键,并将其存储到名为save的新BOOL中.
我想你的SavedGame布尔实际上存储在NSDictionaryas中NSNumber,因此使用boolValue来获取布尔值NSNumber.
试试这个文档: Apple NSDictionary Reference.
| 归档时间: |
|
| 查看次数: |
22051 次 |
| 最近记录: |