码迷,mamicode.com
首页 > 其他好文 > 详细

对plist文件的简单封装

时间:2016-03-31 21:39:47      阅读:124      评论:0      收藏:0      [点我收藏+]

标签:

常常会用到对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;

}

对plist文件的简单封装

标签:

原文地址:http://www.cnblogs.com/damonWq/p/5342831.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!