OC-plist(peopwety List)

Used to describe bundles and tell you how to parse the contents of 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 operation

plist operation

How to get plist content

Search by absolute path (suitable for finding plists that are not in the current project bundle)

		// 本地沙盒路径列表
		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];

Find the relevant plist directly from the bundle

    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;

What does the information filled by default in plist mean?

Apple Documentation

How to use after adding info.plist file in xcode build settings

![Insert image description here](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];

name

If it is called icon file in the plist, it is called CFBundleIconFile in the xcode code.

Guess you like

Origin blog.csdn.net/qq_43535469/article/details/130139596