pList的使用

使用代码创建一份pList,将数组或字典,或包含字典的数组写入pList

NSArray *persons = @[
                     @{@"name" : @"mj", @"age":@38},
                     @{@"name" : @"yjh", @"age":@25, @"friends":@[@"大神11期", @"sz"]}
                     ];
BOOL flag = [persons writeToFile:@"/Users/xiaomage/Desktop/persons.plist" atomically:YES];
if (flag) {
    NSLog(@"写入成功!");
}

获取pList数据

NSString *dataPath = [[NSBundle mainBundle] pathForResource:@"shopData.plist" ofType:nil];
//pathForResource:@"shopData" ofType:@"plist"];
NSArray *dataArr = [NSArray arrayWithContentsOfFile:dataPath];
NSMutableArray *modelArray = [NSMutableArray array];
for (NSDictionary *dict in dataArr) {
    // 创建模型对象
    //[modelArray addObject:模型对象];
}

results matching ""

    No results matching ""