ios plist生成

2017-08-15  本文已影响0人  oc123

用代码在应用沙盒中生成plist文件,如下:

#pragma mark - 创建plist文件
-(void)creatPlistFileWithArr:(NSArray *)array{
    //将字典保存到document文件->获取appdocument路径
    NSString *docPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
    //要创建的plist文件名 -> 路径
    NSString *filePath = [docPath stringByAppendingPathComponent:@"cityPlist.plist"];
    //将数组写入文件
    [array writeToFile:filePath atomically:YES];
    //读取文件
    NSArray *plistArr = [NSArray arrayWithContentsOfFile:filePath];
    NSLog(@"读取 写入的plist 文件:%@",plistArr);
}
上一篇 下一篇

猜你喜欢

热点阅读