开发者社区 问答 正文

请问iOS遵循NSCopying协议采用的copy 和自己写的myCopy函数有什么区别?

-(id)copyWithZone:(NSZone *)zone
 {
 Student * stu = [[Student allocWithZone:zone] init];
 stu.name = self.name;
 stu.age = self.age;
 return stu;
 }

-(id) myCopy
 {
 Student *stu = [Student new];
 stu.name =self.name;
 stu.age = self.age;
 return stu;
 }

展开
收起
爵霸 2016-03-11 10:08:54 2059 分享 版权
1 条回答
写回答
取消 提交回答
  • 你调用任何类的copy和mutableCopy都会直接调用-(id)copyWithZone:(NSZone *)zone 这个等于是默认的

    2019-07-17 18:58:31
    赞同 展开评论