.plist文件到底是什么,我将如何使用它?当我在xcode中查看它时,它似乎会生成某种模板,并显示一些xml代码。有没有办法通过将内容推入数组中来提取plist文件中的数据?另外,我在哪里可以查看.plist的来源?Plist:它是什么以及如何使用它
7
A
回答
13
您可以轻松地使用下面的代码获得的plist的内容到一个数组(我们在这里开叫“file.plist”的文件,该文件的Xcode项目的一部分):
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"file" ofType:@"plist"];
contentArray = [NSArray arrayWithContentsOfFile:filePath];
一个plist中只是相当于一个XML文件一些DTD(数据类型字典)由苹果设计的DTD可以在这里看到:
东西 - 描述了“对象”,而XML文件可以包含数据类型的DTD -among其他。
7
Plist是属性列表的简称。这只是Apple用来存储数据的文件类型。
您可以在这里更多的信息:
http://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man5/plist.5.html
如果你想的Plist阅读点击这里:
// Get the location of the plist
// NSBundle represents the main application bundle (.app) so this is a shortcut
// to avoid hardcoding paths
// "Data" is the name of the plist
NSString *path = [[NSBundle mainBundle] pathForResource:@"Data" ofType:@"plist"];
// NSData is just a buffer with the binary data
NSData *plistData = [NSData dataWithContentsOfFile:path];
// Error object that will be populated if there was a parsing error
NSString *error;
// Property list format (see below)
NSPropertyListFormat format;
id plist;
plist = [NSPropertyListSerialization propertyListFromData:plistData
mutabilityOption:NSPropertyListImmutable
format:&format
errorDescription:&error];
plist
可能是无论在plist中的顶层容器。例如,如果plist是字典,则plist
将是NSDictionary
。如果plist中是一个数组这将是一个NSArray
这里的格式枚举:
enum {
NSPropertyListOpenStepFormat = kCFPropertyListOpenStepFormat,
NSPropertyListXMLFormat_v1_0 = kCFPropertyListXMLFormat_v1_0,
NSPropertyListBinaryFormat_v1_0 = kCFPropertyListBinaryFormat_v1_0
}; NSPropertyListFormat;
相关问题
- 1. ObjectSpace - 它是什么以及人们如何使用它?
- 2. 什么是(void(**)())以及如何typedef它?
- 3. 什么是合同类以及它是如何使用的
- 4. 什么是Flash .SWC文件以及它是如何使用的?
- 5. PatternPathMotion Android,它究竟做了什么以及如何使用它?
- 6. 什么是deps.json,以及如何使它使用相对路径?
- 7. 什么是Ext.Component.initialConfig,它做了什么,以及在什么情况下使用它?
- 8. 什么是dSYM以及如何使用它? (iOS SDK)
- 9. 什么是HTML5 itemid属性,以及如何使用它?
- 10. 什么是msgcat以及如何使用它
- 11. 什么是ActionListener以及如何使用它来处理Enter键?
- 12. 这是什么类型的对象以及如何使用它?
- 13. 什么是客户端路由以及它如何使用?
- 14. 什么是X.509,以及如何使用它?
- 15. 什么是StringIndexer,VectorIndexer以及如何使用它们?
- 16. 什么是Control的DesignMode属性以及如何使用它?
- 17. 什么是strophe以及如何将它与JQuery一起使用?
- 18. 清楚地说明什么是ArrayList以及如何使用它?
- 19. AttributeSet值返回@ 2131296269 - 它是什么以及如何使用?
- 20. AngularJs Material中的defaultIconSet()是什么以及我如何使用它?
- 21. 什么是模拟以及它如何与PrincipalContext配合使用
- 22. 什么是这个元素,以及如何使用它?
- 23. 什么是(XCode)SVN存储库以及如何使用它
- 24. 什么是LD_LIBRARY_PATH以及如何使用它?
- 25. 什么是.inc以及为什么要使用它?
- 26. EJB。什么是它为什么存在以及它如何工作?
- 27. 什么是MySQL中的锁定以及何时使用它?
- 28. 什么是ICustomTypeDescriptor以及何时使用它?
- 29. 代表什么是代表以及何时使用它?
- 30. 什么是表达树,您如何使用它们,以及为什么要使用它们?
感谢您的代码。你能够逐行告诉我你在做什么吗?此外,我不知道这些数据类型是什么(NSBundle,NSData,NSPropertyListFormat,NSPropertyListSerialization)。 – locoboy 2011-04-13 21:09:56
@ cfarm54我更新了一些更多的内嵌评论 – AdamH 2011-04-14 01:03:32