0
A
回答
0
下面是如何比較兩個數組並更新本地數組的示例。請記住,此代碼可能可以優化,但至少應該給你一個如何去做的想法:-)
- (NSArray *)updateArray:(NSArray *)currentArray withData:(NSArray *)webServerData {
NSMutableArray *arr = [[NSMutableArray alloc] init];
//Loop through each NSDictionary in the local array
for (NSDictionary *dict in currentArray) {
NSString *name = [dict objectForKey:@"NAME"];
BOOL updateDict = NO;
//For each NSDictionary, loop through the NSDictionaries in the array from the web server
for (NSDictionary *dict2 in webServerData) {
//If the name in the local dict is the same as the one in the one from the web server, check if the age is different
if ([name isEqualToString:[dict2 objectForKey:@"NAME"]]) {
if ([[dict objectForKey:@"AGE"] integerValue] != [[dict2 objectForKey:@"AGE"] integerValue]) {
//If the age is different, add the new dictionary
[arr addObject:dict2];
updateDict = YES;
}
break;
}
}
//Add the dict from local array if no new data was found in the web server array
if (!updateDict) {
[arr addObject:dict];
}
}
return [arr copy];
}
0
不能寫入plist包含在你的包中。如果您需要plist可編輯,您需要在文檔目錄中創建自己的plist並使用該目錄。
流量:
在首次啓動時您的應用程序,您可以通過捆綁的plist,以創建一個保存在文檔目錄,從原來的plist內容的新的plist。
每當您需要plist的數據時,請使用您在啓動時創建並存儲在Documents目錄中的數據。切勿再次使用包中的包。
當您需要更新plist時,請更新您存儲在文檔中的那個。
相關問題
- 1. Javascript - 從另一個陣列中重新填充一個陣列
- 2. 從另一個陣列創建一個新陣列
- 3. 從另一個陣列創建陣列
- 4. 從另一個陣列製作陣列
- 5. 使用陣列從另一個陣列
- 6. 從一個陣列到另一個陣列的Perl映射(更新簡化)
- 7. 從另一個陣列
- 8. 從另一個陣列
- 9. 從另一個陣列
- 10. 陣列從另一個類
- 11. 從另一個陣列
- 12. 從另一個陣列
- 13. 從另一個陣列
- 14. 從另一個陣列
- 15. 從另一個陣列
- 16. PHP從另一個陣列
- 17. 從另一個陣列
- 18. 從另一個陣列
- 19. 從另一個陣列
- 20. 如何添加一個陣列到另一個陣列
- 21. 如何一個陣列轉移到另一個陣列在PHP
- 22. 在NumPy的,如何將一個陣列到另一個陣列
- 23. 與另一個陣列排列陣列
- 24. PHP從另一個陣列抓一個陣列
- 25. 將對象從一個陣列傳輸到另一個陣列
- 26. 將下標從一個陣列匹配到另一個陣列
- 27. 從一個陣列排序到另一個陣列,Java
- 28. 從另一個陣列中排除一個陣列的元素
- 29. 將位從一個陣列轉換爲另一個陣列?
- 30. 將對象從一個陣列移動到另一個陣列
好吧,那麼你有什麼嘗試?它做錯了什麼? – Wain