zoukankan      html  css  js  c++  java
  • 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;
    
    }
    
     
    
     
  • 相关阅读:
    golang的string是包使用
    OTHER状态的mongodb副本集成员转换为独立的新副本集primary
    linux命令行快捷键
    如何配置vcodes成最美观的样子,让你从此爱上代码
    记一次Lock wait timeout异常的排查过程
    mysql变更上线流程
    go build 使用
    Makefile文件
    解决 windows10系统和AOC显示器时不时地闪现黑屏问题
    feign调用添加header参数
  • 原文地址:https://www.cnblogs.com/0515offer/p/4595163.html
Copyright © 2011-2022 走看看