2011-12-19 60 views
0

我有一個由第三方應用程序生成的IOS plist,我嘗試連接,因此我無法修改plist的格式。給我麻煩的部分是一組字典,即cardList數組。我已經將plist加載到NSMutableDictionary中,沒有問題,並且可以「轉儲」cardList和colorLabelList數組。從第三方plist獲取嵌套字典的最佳方法是什麼?

第一個問題:訪問Item數組的每個成員的最佳方式是什麼?即對於列表中的每張卡片的草稿,標籤等。

2問題:我的'加載到NSMutableDictionary'方法是最佳選擇嗎?

這裏是plist中的佈局:

cardlist Array 
    item 0 Dictionary 
    draft boolean 
    label string 
    notes string 
    ... 
    item 1 Dictionary 
    draft 
    label 
    notes 
    ... 
name  string 
sortOrder number 

回答

0

使用的NSMutableDictionary只有當你真正意義上改變數據,否則使用標準的NSDictionary(這更是風格的東西,實際執行不真的改變了)。

如果通過cardlist陣列要循環,做到以下幾點:

//This will enumerate through the array element by element 
for (NSMutableDictionary *dictionary in cardlist) { 
    //Ok, now we have a dictionary from cardlist 
    //Let's print the items to the console 
    NSLog(@"draft: %i", [dictionary valueForKey:@"draft"]); //Note, there are better ways print print a bool to the log, but this will work for now 
    NSLog(@"label: %@", [dictionary valueForKey:@"label"]); 
    NSLog(@"notes: %@", [dictionary valueForKey:@"notes"]); 

} 

這應該通過所有cardlist陣列和打印值。

+0

謝謝,我瞭解NSMutableDictionary部分。當然,在此之後將會發生一個Master-Detail的事情,標題是主人,記錄的其餘部分是細節。 也許我會更好的只是將記錄加載到定義的類中。 這是循環訪問列表的最快方式嗎?再一次,非常感謝。 – 2011-12-20 00:52:40

+0

沒問題。如果答案有幫助,請點擊問題旁邊的複選標記以表示接受。要了解有關枚舉集合的更多信息,您應該查看文檔:http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/Collections/Articles/Enumerators.html#//apple_ref/doc/ UID/20000135-BBCFABCB – sosborn 2011-12-20 01:07:45

相關問題