我对在 Objective-C 中使用 instancetype 感到困惑。
代码:
@interface MyClass : NSObject
-(instancetype)initWithOwner:(NSString*)anOwner;
@property (nonatomic, strong) NSString* owner;
@end
@interface MyChildClass : MyClass
-(instancetype)init;
@property (nonatomic, strong) NSString* myString;
@end
然后,我可以运行它
MyChildClass* myChildObject = [[MyChildClass alloc] initWithOwner:@"owner"];
为什么这会返回 MyChildClass 而不是 MyClass ???
为什么编译器不显示任何警告或错误消息,我正在使用超类的初始化方法,而不是 MyChildClass 初始化方法???
我在哪里可以使用这个???