常常会用到对plist文件的封装,毕竟初学者,多记有经验
+(NSArray *)LoadFriendsDataFromPlist:(NSString *)pliatName{
NSString * filePath = [[NSBundle mainBundle]pathForResource:pliatName 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;
}