I know that you can do one of the following things when declaring the type of a variable in objective c:
id obj0;
MyClass *obj1;
id<MyProtocol> obj2;
What i’m curious about is if this is valid (syntactically and semantically):
MyClass<MyProtocol> *obj3;
What i want is to store a cocoa class that must implement a given protocol in this variable; if i had control over “MyClass” i wouldnt need this but i’m basically wondering if i can get away with not having to make my own abstract class that multiple other disparate classes need to inherit from, when they can otherwise just inherit from “MyClass” directly.
Yes.
means that
obj3should be a pointer to an object of typeMyClassor a subclass, that also implementsMyProtocol.