我有一个关于子类化和类方法的问题。
我有一个基类 MyBaseClass
,它有一个方便的类方法
+ (id)giveMeAClassUsing:(NSString *)someParameter;
MyBaseClass
不是单例。
现在,我希望创建一个 MyBaseClass
的子类,让我们称之为 MyChildClass
。 我希望在 MyChildClass
上也有相同的类方法。 此外,当我这样做时,我还希望初始化 MyChildClass
上的实例变量。
是否像这样做:
+ (id)giveMeAClassUsing:(NSString *)someParameter {
MyChildClass *anInstance = [super giveMeAClassUsing:someParameter];
anInstance.instanceVariable = [[UIImageView alloc] initWithFrame:someFrame];
return anInstance;
}
是否有效?
非常感谢您的帮助(提前)以及解决我的困惑并澄清一些概念!
干杯!