iOS 数据存储

一、plist文件

项目中新建的plist文件读取

    NSString *plistPath = [[NSBundle mainBundle] pathForResource:@"address" ofType:@"plist"];
    NSDictionary *data = [NSDictionary dictionaryWithContentsOfFile:plistPath];

代码添加的plist文件

    NSString *componentPath = @"demo.plist";
    
    NSArray *pathArray = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *path = [pathArray.firstObject stringByAppendingPathComponent:componentPath];
    
    //增
    NSMutableDictionary *data = [NSMutableDictionary dictionary];
    [data setObject:@"对象1" forKey:@"关键字1"];
    [data setValue:@"对象2" forKey:@"关键字2"];
    [data setValue:@"对象3" forKeyPath:@"关键字3"];
    
    [data writeToFile:path atomically:YES];
    
    //删
    data = [NSMutableDictionary dictionaryWithContentsOfFile:path];
    [data removeObjectForKey:@"关键字1"];
    [data writeToFile:path atomically:YES];
    
    //改
    
    //查
    NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithContentsOfFile:path];
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容