开发者社区> 问答> 正文

请问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 1967 0
1 条回答
写回答
取消 提交回答
  • 你调用任何类的copy和mutableCopy都会直接调用-(id)copyWithZone:(NSZone *)zone 这个等于是默认的

    2019-07-17 18:58:31
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
手淘iOS性能优化探索 立即下载
From Java/Android to Swift iOS 立即下载
深入剖析iOS性能优化 立即下载