我在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 -release:
[copy release]; // Xcode 4.2's Analyze says this is an incorrect decrement of the reference count?!
}
return dict; // Xcode 4.2's Analyze says …Run Code Online (Sandbox Code Playgroud)