【发布时间】:2012-04-28 05:16:47
【问题描述】:
我有一个名为 NumberX 的整数和一个名为 PlistX 的 plist。
示例
int NumberX;
PlistX:
我想知道如何让 NumberX = 三的值
【问题讨论】:
标签: ios properties cocos2d-iphone plist
我有一个名为 NumberX 的整数和一个名为 PlistX 的 plist。
示例
int NumberX;
PlistX:
我想知道如何让 NumberX = 三的值
【问题讨论】:
标签: ios properties cocos2d-iphone plist
试试这个:
NSString *path = [[NSBundle mainBundle] pathForResource:@"PlistX" ofType:@"plist"];
NSDictionary *dict = [[NSDictionary alloc] initWithContentsOfFile:path];
int number = [[[[dict objectForKey:@"One"] objectForKey:@"Two"]objectForKey:@"Three"] intValue];
NSLog(@"%d",number);
【讨论】:
1) 从保存到磁盘的 plist 中获取数据(即NSMutableDictionary *):
NSMutableDictionary *dictionary = [NSPropertyListSerialization propertyListFromData:data mutabilityOption:NSPropertyListMutableContainers format:NULL errorDescription:&error];
2) 从字典中检索需要的对象。
//in your case
NSNumber *tmpNumber = [[[dictionary objectForKey:@"One"] objectForKey:@"Two"] objectForKey:@"Three"];
// convert to int
int NumberX = [tmpNumber intValue];
【讨论】: