zoukankan      html  css  js  c++  java
  • 数据存储1

    plist 文件不能存储一些 普通对象。

    如:自己创建一个新的继承制NSObject的类(如A类)。在这个类中写两个属性。 

    因为A类没有 writeToFile这个方法,所以不能够写入到plist文件中。

    这个时候可能会想,是不是把这个类的数据放到字典或者数组中。因为字典或者数组有这个 writeToFile 方法。

    结果是:不能存储。

    注:只要是普通对象,就不能调 writeToFile 方法。

    - (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);
    }
  • 相关阅读:
    fork-vfork -exit&_exit
    drop_cache-sar
    性能问题eg
    性能工具-mem
    性能工具-io工具
    linux后台开发常用调试工具
    GDB的原理
    可变参数以及stdcall
    linux 中断softirq tasklet
    linux kernel RCU 以及读写锁
  • 原文地址:https://www.cnblogs.com/iOS363536404/p/5217850.html
Copyright © 2011-2022 走看看