iPhone读取plist文件

在xcode中读取plist文件非茶得简单: 读取一个名为recipes.plist的文件:
// 变量定义
NSArray* tableData;
NSArray* thumbnails;
NSArray* prepTime;
// 取得资源路径
NSString* path = [[NSBundle mainBundle] pathForResource:@"recipes" ofType:@"plist"];

//装载内容到预先的定义的数组中
NSDictionary* dict = [[NSDictionary alloc] initWithContentsOfFile:path];
tableData = [dict objectForKey:@"RecipeName"]; // RecipeName为key,下面相同
thumbnails = [dict objectForKey:@"Thumbnail"];
prepTime = [dict objectForKey:@"PrepTime"];
到此你就可以使用读取的内容了,感觉相比在android下,要方便许多啊,方法名称也非常语义化,感觉就像读英语一样,不得不佩服苹果公司啊!还有乔帮主。  

你可能感兴趣的:(plist)