zoukankan      html  css  js  c++  java
  • ios--plist

    //
    //  main.m
    //  03-plist文件的回顾
    //
    //  Created by xiaomage on 15/12/29.
    //  Copyright © 2015年 小码哥. All rights reserved.
    //
    
    #import <Foundation/Foundation.h>
    
    int main(int argc, const char * argv[]) {
        @autoreleasepool {
           // 数组
            NSArray *names1 = @[@"yjh", @"gxq", @"mj", @"nj"];
            BOOL flag1 = [names1 writeToFile:@"/test.plist" atomically:YES];
            
            NSDictionary *persons2 = @{
                                      @"name" : @"yjh",
                                      @"age" : @18,
                                      @"height" : @1.88
                                      };
            BOOL flag2 = [persons2 writeToFile:@"/Users/mctc/Desktop/a.plist" atomically:YES];
            
            NSArray *persons3 = @[
                                 @{@"name" : @"mj", @"age":@38},
                                 @{@"name" : @"yjh", @"age":@25, @"friends":@[@"大神11期", @"sz"]}
                                 ];
            BOOL flag3 = [persons3 writeToFile:@"/Users/mctc/Desktop/a.plist" atomically:YES];
            if (flag3) {
                NSLog(@"写入成功!");
            }
            
            
            NSArray *dataArr4 = @[
                             @{@"name":@"单肩包", @"icon":@"danjianbao"},
                             @{@"name":@"钱包", @"icon":@"qianbao"},
                             @{@"name":@"链条包", @"icon":@"liantiaobao"},
                             @{@"name":@"手提包", @"icon":@"shoutibao"},
                             @{@"name":@"双肩包", @"icon":@"shuangjianbao"},
                             @{@"name":@"斜挎包", @"icon":@"xiekuabao"}
                             ];
            BOOL flag4 = [dataArr4 writeToFile:@"/Users/mctc/Desktop/a.plist" atomically:YES];
            if (flag4) {
                NSLog(@"写入成功!");
            }
           
            NSArray *persons5 = [NSArray arrayWithContentsOfFile:@"/Users/mctc/Desktop/a.plist"];
            NSLog(@"%@", persons5);
            /*
             (
             {
             icon = danjianbao;
             name = "U5355U80a9U5305";
             },
             {
             icon = qianbao;
             name = "U94b1U5305";
             },
             {
             icon = liantiaobao;
             name = "U94feU6761U5305";
             },
             {
             icon = shoutibao;
             name = "U624bU63d0U5305";
             },
             {
             icon = shuangjianbao;
             name = "U53ccU80a9U5305";
             },
             {
             icon = xiekuabao;
             name = "U659cU630eU5305";
             }
             )
             */
        }
        return 0;
    }
  • 相关阅读:
    android-6
    android-5
    android-购物商城
    安卓简易计算器
    安卓第四周作业
    安卓第一周作业
    第十五周作业
    第十三周作业
    第十三周上机练习
    第三次安卓作业
  • 原文地址:https://www.cnblogs.com/yaowen/p/7449649.html
Copyright © 2011-2022 走看看