5

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.

nhahtdh
  • 55,989
  • 15
  • 126
  • 162
Ryan
  • 414
  • 1
  • 6
  • 16
  • `Class` is a type that can hold a pointer to a class object. Like other pointers to objects, it can be strong or weak. – newacct Jan 23 '14 at 00:38

1 Answers1

4

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

Community
  • 1
  • 1
Johnykutty
  • 12,091
  • 13
  • 59
  • 100