zoukankan      html  css  js  c++  java
  • IOS之【属性列表】

    @implementation JamesWongViewController


    - (void)viewDidLoad

    {

        [superviewDidLoad];

        

        [selfwritePerson];

    }


    #pragma mark 尝试写Person

    // 不能通过writeToFile将一个普通对象写入文件中

    // writeToFile会删掉以前存在的文字,创建一个新的文件

    - (void)writePerson {

        Person *person = [[[Person alloc] init] autorelease];

        person.name = @"JamesWong";

        person.age = 10;

        

        //NSArray *array = [NSArray arrayWithObject:person];

        

        // 注意:第一个参数是NSDocumentDirectory,说明要搜索Documents目录

        // NSUserDomainMask:在应用沙盒中搜索

        // 如果第3个参数写NO~/Documents

        // iOS平台,这个函数返回的数组中只有1个结果

        //NSString *documents = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];

        

        NSString *path = [documents stringByAppendingPathComponent:@"array.plist"];

        

        NSArray *array = [NSArray arrayWithObjects:@"1", nil];

        [array writeToFile:path atomically:YES];

    }


    #pragma mark 将字典写入属性列表文件中

    - (void)writeDict {

        NSMutableDictionary *dict = [NSMutableDictionarydictionary];

        [dict setObject:@"JamesWong"forKey:@"name"];

        [dict setObject:[NSNumbernumberWithInt:10] forKey:@"age"];

        

        // 获取应用沙盒的根路径

        NSString *home = NSHomeDirectory();

        NSString *documents = [home stringByAppendingPathComponent:@"Documents"];

        // 属性列表的默认拓展名是plist

        NSString *path = [documents stringByAppendingPathComponent:@"dict.plist"];

        

        [dict writeToFile:path atomically:YES];

    }


    #pragma mark 从属性列表文件中读取字典

    - (void)readDict {

        // 获取应用沙盒的根路径

        NSString *home = NSHomeDirectory();

        NSString *documents = [home stringByAppendingPathComponent:@"Documents"];

        // 属性列表的默认拓展名是plist

        NSString *path = [documents stringByAppendingPathComponent:@"dict.plist"];

        

        NSDictionary *dict = [NSDictionarydictionaryWithContentsOfFile:path];

        

        NSLog(@"%@", dict);

    }

    @end


  • 相关阅读:
    @Value和@ConfigurationProperties
    mongodb为集合新增字段、删除字段、修改字段(转)
    mongoTemplate CURD 和模糊查询(转)
    在项目中使用Swagger接口说明
    mongodb 批量添加、修改和删除
    @SpringQueryMap注解 feign的get传参方式(转)
    Spring下的@Order和@Primary与javax.annotation-api下@Priority【Spring4.1后】等方法控制多实现的依赖注入(转)
    @RequestBody和@RequestParam区别
    Juit4 SpringBoot注解
    Spring Boot干货系列:(十二)Spring Boot使用单元测试(转)
  • 原文地址:https://www.cnblogs.com/riasky/p/3455269.html
Copyright © 2011-2022 走看看