I have a Model class written in Objective-C, it must be inherited by subclasses. There is a method:
- (id)deepcopy {
id newModel = [[[self class] alloc] init];
newModel.id = self.id;
return newModel;
}
Routinesshould redefine it as follows:
- (id)deepcopy {
id newModel = [super deepcopy];
return newModel;
}
The key is [[[self class] alloc] init] , which will be an instance of an object based on the actual class. I recently try to upgrade this project to Swift, but could not find a way to do the same in Swift.
How can i do this?
source
share