I couldn't find anything specific to this in Apple's documentation.
Here is a scenario.
Objective-C class:
@implementation Superclass
- (instancetype)init {
self = [super init];
[self doSomething];
return self;
}
- (void)doSomething {
NSLog(@"\ndoSomething called from Superclass\n");
}
@end
Swift subclass:
class Subclass: Superclass {
override init() {
super.init()
doSomething()
}
@objc func doSomething() {
print("\n\ndoSomething called from Subclass\n")
}
}
Using @objc
in the method signature of doSomething
in the subclass causes the method in the superclass never to be called i.e. only doSomething called from Subclass
is printed to the console.
Removing @objc
fixes the issue.
Why is this?