如何从静态方法中检测调用类,以便如果该类是子类,则检测到子类?(见 MakeInstance 内的评论)
@interface Widget : NSObject
+ (id) MakeInstance;
@end
@implementation Widget
+ (id) MakeInstance{
Class klass = //How do I get this?
id instance = [[klass alloc] init];
return instance;
}
@end
@interface UberWidget : Widget
//stuff
@end
@implementation UberWidget
//Stuff that does not involve re-defining MakeInstance
@end
//Somewhere in the program
UberWidget* my_widget = [UberWidget MakeInstance];