2013-08-02 73 views
0

Iam試圖創建一個具有以下功能的plist。我如何在圖像中創建如下所示的plist?

裏面的plist有兩個鍵
1.id 2.status

電流值ID:91種狀態:在這裏買ID必須是唯一的.Means,如果我嘗試添加像ID的第3項: 91狀態:downlaod。然後它應該取代現有的91和狀態:購買新的。

請幫我下面的圖片image

檢查如何刪除狀態和ID,如果我在標識有一個匹配?

+0

從哪裏新的條目將是補充的嗎?請提供該代碼 – Mrunal

回答

1

枚舉根陣列和比較ID in dictionary

NSMutableArray *rootArray = [[NSMutableArray alloc] initWithCapacity:0]; 
NSDictionary *dic = [[NSDictionary alloc] initWithObjectsAndKeys:@"91",@"id",@"Buy",@"status",nil]; 
NSDictionary *dic1 = [[NSDictionary alloc] initWithObjectsAndKeys:@"92",@"id",@"Download",@"status",nil]; 
[rootArray addObject:dic]; 
[rootArray addObject:dic1]; 

enter image description here

NSDictionary *dic3 = [[NSDictionary alloc] initWithObjectsAndKeys:@"91",@"id",@"Download",@"status",nil]; 
NSDictionary *foundMatch =nil; 

for(NSDictionary *dictionary in rootArray) 
{ 
    if ([[dictionary objectForKey:@"id"] isEqualToString:[dic3 objectForKey:@"id"]]) { 
     foundMatch = dictionary; 
     break; 
    } 
} 
if (foundMatch!=nil) { 
    [rootArray removeObject:foundMatch]; 
    [rootArray addObject:dic3]; 
} 
else { 
    [rootArray addObject:dic3]; 
} 
[rootArray writeToFile:@"path" atomically:YES]; 

enter image description here

相關問題