我有一个NSDictionary类别中的以下方法,做一个深层复制,这工作正常。 我刚从Xcode 4.1升级到4.2,Analyze函数给出了这个代码的两个分析器警告,如下所示: – (id)deepCopy; { id dict = [[NSMutableDictionary alloc] init]; id copy; for (id key in self) { id object = [self objectForKey:key]; if ([object respondsToSelector:@selector(deepCopy)]) copy = [object deepCopy]; else copy = [object copy]; [dict setObject:copy forKey:key]; // Both -deepCopy and -copy retain the object, and so does -setObject:forKey:, so need to […]
有没有内置的函数,允许我深入复制一个NSMutableArray ? 我环顾四周,有人说[aMutableArray copyWithZone:nil]作为深层复制。 但我试了一下,似乎是一个浅的副本。 现在我手动做一个for循环的副本: //deep copy a 9*9 mutable array to a passed-in reference array -deepMuCopy : (NSMutableArray*) array toNewArray : (NSMutableArray*) arrayNew { [arrayNew removeAllObjects];//ensure it's clean for (int y = 0; y<9; y++) { [arrayNew addObject:[NSMutableArray new]]; for (int x = 0; x<9; x++) { [[arrayNew objectAtIndex:y] addObject:[NSMutableArray new]]; NSMutableArray *aDomain […]