相关疑难解决方法(0)

实现copyWithZone时的最佳实践:

我试图澄清一些关于实施的问题copyWithZone:,任何人都可以评论以下内容......

// 001: Crime is a subclass of NSObject.
- (id)copyWithZone:(NSZone *)zone {
    Crime *newCrime = [[[self class] allocWithZone:zone] init];
    if(newCrime) {
        [newCrime setMonth:[self month]];
        [newCrime setCategory:[self category]];
        [newCrime setCoordinate:[self coordinate]];
        [newCrime setLocationName:[self locationName]];
        [newCrime setTitle:[self title]];
        [newCrime setSubtitle:[self subtitle]];
    }
    return newCrime;
}

// 002: Crime is not a subclass of NSObject.
- (id)copyWithZone:(NSZone *)zone {
    Crime *newCrime = [super copyWithZone:zone];
    [newCrime setMonth:[self month]];
    [newCrime setCategory:[self category]];
    [newCrime setCoordinate:[self coordinate]];
    [newCrime setLocationName:[self locationName]];
    [newCrime setTitle:[self title]];
    [newCrime …
Run Code Online (Sandbox Code Playgroud)

iphone cocoa-touch objective-c copywithzone

74
推荐指数
2
解决办法
5万
查看次数

标签 统计

cocoa-touch ×1

copywithzone ×1

iphone ×1

objective-c ×1