标签:
常常会用到对plist文件的封装
+(NSArray *)LoadFriendsDataFromPlist:(NSString *)plistName{
NSString * filePath = [[NSBundle mainBundle]pathForResource:plistName ofType:@"plist"];
NSArray * array = [NSArray arrayWithContentsOfFile:filePath];
NSMutableArray * dataArray = [NSMutableArray array];
for (NSDictionary * dic in array) {
//读取分组名
NSString * groupName = [dic objectForKey:@"groupName"];
//读取好友
NSArray * friendArray =[dic objectForKey:@"friends"];
//封装好友为
NSMutableArray * personArray = [NSMutableArray array];
for (NSDictionary * dic in friendArray) {
Person * person = [[Person alloc]initWithName:[dic objectForKey:@"name"] iconName:[dic objectForKey:@"icon"] introduction:[dic objectForKey:@"intro"]];
[personArray addObject:person];
}
NSDictionary * groupDic = @{@"friends":personArray,@"groupName":groupName};
[dataArray addObject:groupDic];
}
return dataArray;
}
标签:
原文地址:http://www.cnblogs.com/damonWq/p/5342831.html