• Plist文件


    //
    //  main.m
    //  OC3_Plist文件 用 writeToFile创建
    //
    //  Created by zhangxueming on 15/6/23.
    //  Copyright (c) 2015年 zhangxueming. All rights reserved.
    //
    
    #import <Foundation/Foundation.h>
    //plist文件
    //plist文件的根节点只能为数组(NSArray)或者字典(NSDictionary)
    //存储的对象: NSArray NSDictionary NSDate NSData Boolean NSNumber NSString
    
    int main(int argc, const char * argv[]) {
        @autoreleasepool {
            NSArray *array = [[NSArray alloc] initWithObjects:@"one",@"two",[NSNumber numberWithInt:123],[NSDate date], nil];
            //在指定目录下没有对应的plist文件, 会自动创建该文件
            BOOL ret = [array writeToFile:@"/Users/zhangxueming/Desktop/Test/array.plist" atomically:YES];
            if (ret) {
                NSLog(@"文件写入成功");
            }
            else
            {
                NSLog(@"文件写入失败");
            }
            
            NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:@"1",@"one",@"2",@"two",[NSNumber numberWithInt:345],@"num",[@"ios" dataUsingEncoding:NSUTF8StringEncoding],@"ios",[NSDate date],@"date",array,@"array", nil];
            ret = [dict writeToFile:@"/Users/zhangxueming/Desktop/Test/dict.plist" atomically:YES];
            if (ret) {
                NSLog(@"文件写入成功");
            }
            else{
                NSLog(@"文件写入失败");
            }
            
        }
        return 0;
    }
    
    
    
    ----------
    //
    
    //  main.m
    
    //  OC4_Plist文件读取
    
    //
    
    //  Created by zhangxueming on 15/6/23.
    
    //  Copyright (c) 2015年 zhangxueming. All rights reserved.
    
    //
    
     
    
    #import <Foundation/Foundation.h>
    
     
    
    int main(int argc, const char * argv[]) {
    
        @autoreleasepool {
    
            NSDictionary *dict = [NSDictionary dictionaryWithContentsOfFile:@"/Users/zhangxueming/Desktop/ios1509/Day21_文件归档/OC4_Plist文件读取/apple.plist"];
    
            if(dict)
    
            {
    
                NSLog(@"dict = %@", dict);
    
            }
    
            
    
            
    
            NSArray *array = [NSArray arrayWithContentsOfFile:@"/Users/zhangxueming/Desktop/Test/array.plist"];
    
            if (array) {
    
                NSLog(@"array = %@", array);
    
            }
    
        }
    
        return 0;
    
    }
    
     
    
     
  • 相关阅读:
    爬虫防止浏览器防止debug处理
    php
    代码日记
    Linux定时任务
    Linux 三剑客(Awk、Sed、Grep)
    golang中使用ETCD
    golang中使用mysql数据库
    golang中使用Redis
    Linux进阶知识和命令
    Linux核心命令使用方法
  • 原文地址:https://www.cnblogs.com/0515offer/p/4595163.html
Copyright © 2020-2023  润新知