Objective-c:如何按名称转换为类类型

时间:2014-09-16 01:26:19

标签: objective-c

我尝试做这样的事情:

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

1 个答案:

答案 0 :(得分:0)

CustomClass * obj =(CustomClass *)_ object;