Can Objective-C protocol be generic?
Following this tutorial, I'm basically looking for something like that:
@protocol ItemsStore<__covariant ObjectType> <NSObject>
-(NSArray <ObjectType> *)items;
@end
Which is a generic protocol for some ObjectType
that "implements" ("inherits") another protocol NSObject
As @rmaddy suggested, and as referred to this questions, it is NOT possible. Shame, moving to Swift then...
Maybe you could just redefine it as generic in the interface.
@protocol ItemsStore <NSObject>
- (NSArray *)items;
@end
@interface MyItemsStore<ObjectType> : NSObject <ItemsStore>
- (NSArray <ObjectType> *)items;
@end
This seems an unlikely scenario though. You might be better just defining the type of the items in each subclass. Like what Apple do with NSFetchRequest
in their core data model generation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With