.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. typedef void(* MyCallback):它是什麼以及如何使用它?
- 2. Magento XMLConnect ...它是什麼以及如何使用它?
- 3. ObjectSpace - 它是什麼以及人們如何使用它?
- 4. 什麼是(void(**)())以及如何typedef它?
- 5. 什麼是合同類以及它是如何使用的
- 6. 什麼是Flash .SWC文件以及它是如何使用的?
- 7. 什麼是deps.json,以及如何使它使用相對路徑?
- 8. svn - 增量:如何使用它以及它做了什麼?
- 9. PatternPathMotion Android,它究竟做了什麼以及如何使用它?
- 10. 什麼是Ext.Component.initialConfig,它做了什麼,以及在什麼情況下使用它?
- 11. jquery fancybox - 它是如何工作的以及它需要什麼?
- 12. 什麼是IntelliJ中的「手錶」以及如何使用它們?
- 13. 什麼是intvectors以及如何閱讀/使用它們?
- 14. phonegap中的插件是什麼以及如何使用它?
- 15. 什麼是.pem文件以及如何使用它?
- 16. 什麼是Control的DesignMode屬性以及如何使用它?
- 17. AttributeSet值返回@ 2131296269 - 它是什麼以及如何使用?
- 18. 什麼是StringIndexer,VectorIndexer以及如何使用它們?
- 19. 什麼是dSYM以及如何使用它? (iOS SDK)
- 20. CodeMirror - 什麼是addWidget以及如何使用它?
- 21. 什麼是LD_LIBRARY_PATH以及如何使用它?
- 22. HTML5中的內容是什麼?以及如何使用它?
- 23. 這是什麼樣的設置以及如何使用它?
- 24. 什麼是phpmd以及如何使用它?
- 25. 什麼是OpenEJB中的@Module註釋以及如何使用它?
- 26. iOS 7上的CTSubscriber是什麼(以及如何使用它)?
- 27. 什麼是數據庫緩存,以及如何使用它?
- 28. 這些是什麼以及如何使用Ruby刪除它們?
- 29. 什麼是X.509,以及如何使用它?
- 30. AngularJs Material中的defaultIconSet()是什麼以及我如何使用它?
感謝您的代碼。你能夠逐行告訴我你在做什麼嗎?此外,我不知道這些數據類型是什麼(NSBundle,NSData,NSPropertyListFormat,NSPropertyListSerialization)。 – locoboy 2011-04-13 21:09:56
@ cfarm54我更新了一些更多的內嵌評論 – AdamH 2011-04-14 01:03:32