问题描述
- 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;
}
解决方案
http://blog.csdn.net/tskyfree/article/details/7999620
解决方案二:
你调用任何类的copy和mutableCopy都会直接调用-(id)copyWithZone:(NSZone *)zone 这个等于是默认的
时间: 2024-10-01 05:49:19