copyWithZone: 的正确写法
@interface Teacher : NSObject
@end
@implementation Teacher
@end
@interface Student : NSObject <NSCopying>
@property (nonatomic, strong, nullable) Teacher *teacher;
@end
@implementation Student
- (instancetype)copyWithZone:(NSZone *)zone {
Student *student = [[[self class] allocWithZone:zone] init];
if ( [self.teacher conformsToProtocol:@protocol(NSCopying)] ) {
student.teacher = [self.teacher copy];
} else {
student.teacher = self.teacher;
}
return student;
}
本文标题:copyWithZone: 的正确写法
本文链接:https://www.haomeiwen.com/subject/pwywpktx.html
网友评论