1

I have four screens that are exactly the same except they use four different classes. I thought I could reduce them to one by putting this property in my header:

@property Class *classType;

Then I could set the class and be done.

HOWEVER, when I try to use classType like the following:

NSArray *myArray = [classType allobjects];

I get the following: "Bad receiver type __unsafe_unretained Class *"

This really doesn't make much sense. The class method returns and NSArray. When I use the explicit class name there is no error and everything works fine.

I'm using xcode 4.5 with ARC.

1
  • Your should inherit base class or use protocol for it. Commented Oct 6, 2012 at 21:59

2 Answers 2

4

Try using

@property Class classType;

Note the missing *. Class is like id, the pointer type is implied.

Sign up to request clarification or add additional context in comments.

2 Comments

Okay, that fixed one side of it. Now when in my main class I have controller.classType = MyOtherClass; it tosses me the error "Unexpected interface name MyOtherClass: expected expression". BTW thanks for the catch on the "*" totally overlooked that.
Perfect. I've been writing objc for almost 15 years and this is the first time I've really needed to do this. lol - thanks for the help!
0

Quick search on Google, even better in the runtime's headers:

typedef struct objc_class *Class;

The Class type is a pointer itself - you don't need an extra * sign when declaring the property.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.