问题描述:

so in Objective-C I can have a reference to object that implements certain protocol like this:

id<MyAwesomeProtocol> object;

I could have a reference to some class, like this:

MyAwesomeClass *object;

I was wondering, what should I do to have reference to MyAwesomeClass, or any sub-class.

I could of course just use id but I'd like to know if there is any better way.

Thanks!

网友答案:

To have reference to an object of your class or its subclasses you still can write

MyAwesomeClass *object;
网友答案:

In general it is better to use NSObject* instead of id. All objective-C objects are decendants for NSObject so why ignore all the NSObject goodies?

If you are dealing with MyAwesomeClass or subclasses I would use MyAwesomeClass *object. If you are just using the protocol methods (in the context of the protocol) then I would use NSObject <MyAwesomeProtocol> *object.

相关阅读:
Top