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.

有帮助吗?

解决方案

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

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top