As of Xcode 7, Objective-C introduced generic type parameters for classes. Is there any way to use generics with Objective C protocols? I haven't found an obvious way to do this because the equivalent to @interface MyClass<ObjectType>
is already taken for protocols (e.g. @protocol MyProtocol<NSObject>
).
Example: I would like to convert code like this:
@protocol MYObjectContainer
- (id)objectAtIndex:(NSUInteger)index;
@end
to code like this:
@protocol MYObjectContainer
- (ObjectType)objectAtIndex:(NSUInteger)index;
@end
Which is possible with regular classes (see, for example, NSArray).