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;
    
    }
    
     
    
     
  • 相关阅读:
    C#Winform中treeView控件使用总结
    转:vs发布window应用程序时出错:未能签名 ...setup.exe
    C# 常见集合之前的转换
    开发者眼中的Spring与JavaEE
    运行库到底做了什么?
    C++, Java和C#的编译、链接过程解析
    转载一篇将C/C++ 与lua混合使用入门讲的比较好的文章
    路会越走越窄的
    [DBNETLIB][ConnectionOpen(Connect()).]SQL Server 不存在或拒绝访问 数据库错误 解决办法总结
    Linux学习路线指南
  • 原文地址:https://www.cnblogs.com/0515offer/p/4595163.html
Copyright © 2011-2022 走看看