我对Objective C很新,所以也许这很简单,但我构建了一个类,它将存储一个类引用。 这就是我的.h文件中的内容:
@property (nonatomic, assign) Class *filterClass;我感到很糟糕的是,我无法将类对象分配给这个类的实例,我可以将它们添加到数组或变量中:
Filter *filter1 = [[Filter alloc] init]; filter1.title = @"Sepia"; filter1.filterClass = [GPUImageSepiaFilter class];我收到一个错误:
“使用ARC禁止将Objective-C指针隐式转换为'__unsafe_unretained Class *'”
看起来它想要filterClass属性是强大的,但也给出了错误,因为据我所知,你不能将原始类型定义为强。 显然我可以将字符串存储为类的引用并使用-NSClassFromString,但是如果我可以只传递类对象,那将会很好。 因为我可以把它们放在数组中,看起来它应该是可能的。 如果我完全错了,请告诉我。
I'm pretty new to Objective C so maybe this is really simple, but I built a class which will store among other things a class reference. This is what I have in my .h file:
@property (nonatomic, assign) Class *filterClass;Where I'm getting suck is that I am not able to assign class objects to an instance of this class they way I can add them to arrays or variables:
Filter *filter1 = [[Filter alloc] init]; filter1.title = @"Sepia"; filter1.filterClass = [GPUImageSepiaFilter class];I am getting an error:
"implicit Conversion of an Objective-C pointer to '__unsafe_unretained Class *' is disallowed with ARC"
It seems like it wants the filterClass property to be strong but that also gives and error, because as I understand it you can't define primitive types as strong. Obviously I could just store strings as references to the classes and use -NSClassFromString, however it would be nice if I could just pass the class objects around. Since I can put them in arrays and it seems like it should be possible. Let me know if I'm going about this completely wrong.
最满意答案
财产声明必须是
@property (nonatomic, assign) Class filterClass;代替
@property (nonatomic, assign) Class *filterClass;请检查此答案Objective-c - Class Keyword
The property declaration must be
@property (nonatomic, assign) Class filterClass;instead of
@property (nonatomic, assign) Class *filterClass;Please check this answer Objective-c - Class Keyword
更多推荐
发布评论