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