首页 > 代码库 > ios对象copy的方法,要实现nscopy协议

ios对象copy的方法,要实现nscopy协议

ios对象copy的方法,要实现nscopy协议

by 伍雪颖

- (id)copyWithZone:(NSZone *)zone
{
    RestEntity *copy = [[[self class] allocWithZone:zone] init];
    copy.dishId = _dishId;
    return copy;
}

- (id)mutableCopyWithZone:(NSZone *)zone
{
    RestEntity *copy = [RestEntity allocWithZone:zone];
    copy.dishId = _dishId;
    return copy;
}

NSObject <NSCopying,NSMutableCopying>

ios对象copy的方法,要实现nscopy协议