我尝试做这样的事情:
Class CustomClass = [MyClass class];
// _object is an instance variable typed with "id"
CustomClass *obj = CustomClass *_object; // Error here
是否可以在Objective-C中按名称将对象强制转换为类?
我实际上是在写一个吸气剂
- (id)photoFrame
{
if (NSClassFromString(@"CustomClass")) {
return (CustomClass1 *) _object;
} else {
return (CustomClass2 *) _object;
}
}
错误讯息为Expected expression
。
答案 0 :(得分:0)
CustomClass * obj =(CustomClass *)_ object;