• iOS-plist的保存和读取


    两个按钮

    // 当点点击保存的时候调用
    - (IBAction)save:(id)sender {
        // 获取沙盒的根路径
    //    NSString *home = NSHomeDirectory();
        
        // 拼接Documents路径
    //    NSString *docPath = [home stringByAppendingString:@"/Documents"];
    //    NSString *docPath = [home stringByAppendingPathComponent:@"Documents"];
        
        
        /**
         *  NSDocumentDirectory : 查找Documents文件夹
            NSUserDomainMask : 在用户的应用程序下查找
         YES 把路径展开 NO 当前应用的根路径 == ~ 
         NO  ~/Documents
    
         */
        NSString *docPath =  NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0];
        NSLog(@"%@",docPath);
        
        // 拼接文件路径
        NSString *filePath = [docPath stringByAppendingPathComponent:@"data.plist"];
        
        // 只有具备writeToFile:的对象才能使用plist存储,NSArray
        NSArray *array = @[@1,@2,@"123"];
        
        [array writeToFile:filePath atomically:YES];
        
    //    NSLog(@"%@",docPath);
        
        
        
    }
    //当点击读取的时候调用
    - (IBAction)read:(id)sender {
        NSString *docPath =  NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0];
        NSLog(@"%@",docPath);
        
        // 拼接文件路径
        NSString *filePath = [docPath stringByAppendingPathComponent:@"data.plist"];
        
       NSArray *data = [NSArray arrayWithContentsOfFile:filePath];
        NSLog(@"%@",data);
        
    }
  • 相关阅读:
    mapreduce 的过程
    bootstrap当中,实现一些常用的元素居中
    如何理解人工智能、机器学习和深度学习三者的关系
    MapReduce的局限性
    MapReduce的计算资源划分
    Java中的堆和栈的区别
    java面试01-网络知识
    01Java经典问题
    06数据库复习03
    05数据库复习02
  • 原文地址:https://www.cnblogs.com/zhuyaguang/p/4787544.html
Copyright © 2020-2023  润新知