I've been trying to create a category on NSArray and looking at the interface of NSArray I assume that to add a method that returns an ObjectType, is:
// interface
- (nullable ObjectType)giveMeAnObject;
// implementation
- (nullable ObjectType)giveMeAnObject
{
ObjectType object = nil;
return object;
}
However that doesn't work and I get the error message Expected ')' in the return type.
It seems you can use lightweight generics in interfaces, but not implementations.
@interface NSArray<ObjectType> (MyAdditions)
- (nullable ObjectType)giveMeAnObject; // specify return type
@end
@implementation NSArray (MyAdditions)
- (id)giveMeAnObject // use id for the implementation
{
return nil;
}
@end
You might want to file an enhancement request if you'd like to see them in @implementation
blocks too.
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