2.4 读取plist文件和NSNumber

2019-04-08  本文已影响0人  草根小强

读取plist文件

#import <Foundation/Foundation.h>

int main(int argc, const char * argv[]) {
    @autoreleasepool {
       // /Users/qianfeng/Desktop/汤姆猫资源/Tomcat.plist
        
        //读取plist文件  只有两种格式 一种是字典 一种是数组
        
        //1. 找到plist 文件 在哪?
//        NSString *path = [[NSBundle mainBundle] pathForResource:@"" ofType:@""];
        
        NSString *path = @"/Volumes/xiaoqiang/ios/已复制UI阶段/UI上课代码/UI第二天/readPlist/readPlist/Tomcat.plist";
        //2. 用对应的类去读取
        
        NSDictionary *dict = [NSDictionary dictionaryWithContentsOfFile:path];
        //NSNumber 是一个OC的类,是用来处理基本数据类型的存储的
#warning NSNumber
        //int -》NSNumber
        NSNumber *n = [NSNumber numberWithInt:1];//将整形1转化为NSNumber
//        NSNumber ->int
        int a = n.intValue;
    //  或者int a = [n intValue];
        
        
        NSLog(@"dict====%@",dict);//键值对
        NSLog(@"a======%d",a);//1
        
    }
    return 0;
}
上一篇 下一篇

猜你喜欢

热点阅读