OC-plist(peopwety List)

用来描述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

猜你喜欢

转载自blog.csdn.net/qq_43535469/article/details/130139596