plist文件的读取和使用

1、通过NSBundle来读取文件,mainBundle获取的是该app所在的目录

[[NSBundle mainBundle] pathForResource:@"SysMessageRing"ofType:@"plist"]// plistPath

 

2、可以通过fileManager获取该目录下的所有文件,来查看获取目录是否正确

[[NSFileManagerdefaultManager] contentsOfDirectoryAtPath:[[NSBundlemainBundle] resourcePath] error:nil]

 

3、最重要的一点,plist文件读取的时候都是以NSDictionary的方式读取的,先通过NSDictionary的方式把全部内容读取出来之后

然后再去具体对应的值。

[[NSDictionaryalloc] initWithContentsOfFile:plistPath] // 读取的整个plist文件的值

然后取出其中的某个值

NSArray *systemMessageRing = [[[NSDictionary alloc] initWithContentsOfFile:plistPath] objectForKey:@"SystemMessageRing"];

获取该数组的值,即可使用,更改,或者、、、然后把更改的结果写回到plist文件

 

 

 

 

原文地址:https://www.cnblogs.com/easonoutlook/p/2642791.html