OC-plist(peopwety List)

Xcode在复制操作时使用构建设置进行变量替换,并插入额外的配置键。例如,您在项目编辑器中指定的iOS应用部署目标会被转换为MinimumOSVersion键。可以通过绝对路径或从bundle中获取plist内容,使用NSBundle和dictionaryWithContentsOfFile方法。Info.plist文件中的键值可以使用objectForInfoDictionaryKey方法访问,如debugMode和应用名称。

用来描述bundles,告诉你如何解析bundles的内容

During the copy operation, Xcode uses build settings to perform variable substitution. It also inserts additional keys representing configuration that you specify in other ways. For example, you indicate the deployment target for an iOS app in Xcode’s project editor. Xcode translates that into the MinimumOSVersion key that it adds during the copy. As a result of these changes, the information property list file that ships with your app isn’t identical to the source file in your project.

plist操作

plist操作

获取plist内容的方法

通过绝对路径查找(适合查找不在当前工程bundle中的plist)

		// 本地沙盒路径列表
		NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
		//NSSearchPathForDirectoriesInDomains
		//第一个参数表示要获取的目录类型(NSDocumentDirectory、NSLibraryDirectory、NSCachesDirectory)
		//第二个参数表示要搜索的目录域,(NSUserDomainMask、NSLocalDomainMask、NSNetworkDomainMask)
		//第三个参数表示是否要将~扩展为当前用户的主目录。默认为YES。
		// 获取沙河路径
		NSLog(@"paths:%@",paths);
		NSString* plistPath = [paths objectAtIndex:0];
		NSLog(@"plistPath:%@",plistPath);//fileName:/Users/xxx/Library/Containers/test.OCTest/Data/Documents
		// 拼接完整路径
		NSString* fileName = [plistPath stringByAppendingPathComponent:@"test.plist"];
		NSLog(@"fileName:%@",fileName);//fileName:/Users/xxx/Library/Containers/test.OCTest/Data/Documents/test.plist

		NSDictionary* fileContent = [NSDictionary dictionaryWithContentsOfFile:fileName];

直接从bundle中找相关plist

    NSBundle *bundle = [NSBundle bundleForClass:xxx.class];
    NSString *plistPath  = [bundle pathForResource:@"test" ofType:@"plist"];//在bundle中找test.plist的文件
    NSDictionary *dicPlist = [NSDictionary dictionaryWithContentsOfFile:plistPath];
    if (!dicPlist.count) {
        return YES;
    }
    BOOL res = [[dicPlist objectForKey:@"name"] boolValue];//找名叫name的属性数据
    return res;

plist默认填充的信息都是什么意思

苹果文档

在xcode的build settings中添加info.plist file后如何使用

![在这里插入图片描述](https://img-blog.csdnimg.cn/71897ac203bf4347ac0cf6c49a7dc498.jpe

		BOOL isDebugMode = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"debugMode"];
		//objectForInfoDictionaryKey用于获取应用程序的信息字典(Info.plist)中指定键名的键值。
		NSString* name = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"name"];
		NSLog(@"isDebugMode: %d", isDebugMode);
		NSLog(@"name: %@", name);
NSString *appName = [[[NSBundle mainBundle] infoDictionary] objectForKey:(id)kCFBundleNameKey];

名字

如果plist中叫icon file 则xcode代码中就叫 CFBundleIconFile

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值