【发布时间】:2015-07-06 10:29:22
【问题描述】:
我的应用程序中有一个公共数据,在某些视图中,我必须仅在此视图内更新这些值。
所以我在这个视图中创建了一个局部变量,然后我将这些变量的值设置为等于全局变量,最后我更新了这些全局变量。这是我的代码:
if (_isCitySelector){
_dataArray = [[NSMutableArray alloc] initWithArray:[[Commun sharedInstance] stateArray]];
_subDataArray = [[NSMutableDictionary alloc] initWithDictionary:[[Commun sharedInstance] cityDictionary]];
} else {
_dataArray = [[NSMutableArray alloc] initWithArray:[[Commun sharedInstance] categoriesArray]];
_subDataArray = [[NSMutableDictionary alloc] initWithDictionary:[[Commun sharedInstance] subCategoriesDictionary]];
}
if (_activateParentSelection){
for (PFObject *object in _dataArray) {
NSMutableArray *tempArray = (NSMutableArray *)[_subDataArray valueForKey:object.objectId];
if ([[tempArray objectAtIndex:0][@"titre"] isEqualToString: @"الكل"])
continue;
PFObject *tempObject = [PFObject objectWithClassName:[object parseClassName]];
tempObject[@"titre"] = @"الكل";
if (object[@"nbrAnnonce"]){
tempObject[@"categorie_id"] = object;
tempObject[@"nbrAnnonce"] = @0;
}else
tempObject[@"region_id"] = object;
[tempArray insertObject:tempObject atIndex:0];
[_subDataArray setObject:tempArray forKey:object.objectId];
}
}
这段代码工作得很好,但是这也会更新全局变量的问题吗?我的代码有什么问题!!!
更新
我不能使用copyWithZone,因为我的数据类型是PFObject,而 parse.com 对象不支持此功能
【问题讨论】:
-
试试这个!
NSMutableArray *tempArray = [(NSMutableArray *)[_subDataArray valueForKey:object.objectId] mutableCopy]
标签: ios objective-c cocoa cocoa-touch parse-platform