ios 沙盒 plist 数据的读取和存储

来源:互联网 发布:淘宝送货入户费用谁出 编辑:程序博客网 时间:2024/04/28 08:58

转自:http://www.maxiaoguo.com/clothes/230.html

plist 只能存储基本的数据类型 和 array  字典


- (void)saveArray{    // 1.获得沙盒根路径    NSString *home = NSHomeDirectory();        // 2.document路径    NSString *docPath = [home stringByAppendingPathComponent:@"Documents"];        // 3.新建数据//    MJPerson *p = [[MJPerson alloc] init];//    p.name = @"rose";    NSArray *data = @[@"jack", @10, @"ffdsf"];            NSString *filepath = [docPath stringByAppendingPathComponent:@"data.plist"];            [data writeToFile:filepath atomically:YES];}- (IBAction)read {    // 1.获得沙盒根路径    NSString *home = NSHomeDirectory();        // 2.document路径    NSString *docPath = [home stringByAppendingPathComponent:@"Documents"];        // 3.文件路径    NSString *filepath = [docPath stringByAppendingPathComponent:@"data.plist"];        // 4.读取数据    NSArray *data = [NSArray arrayWithContentsOfFile:filepath];    NSLog(@"%@", data);}


0 0