Categories on NSArray using ObjC Generics?

On the WWDC presentation "What's new in Cocoa" there is a slide that shows the following:


@interface NSArray<ObjectType>(CategoryName)

//methods on NSArray declared here for arrays of ObjectType

@end


If I do File->New->Category and create a new category on NSArray, add my class


#import "Page.h"

@interface NSArray<Page> (CategoryName)

-(NSUInteger)numberOfParagaphsInAllPages;

@end

//implementation

-(NSUInteger)numberOfParagaphsInAllPages
{
   NSUInteger paragraphs = 0;
    for (Page *aPage in self)
   {
        paragraphs =  paragraphs+aPage.paragraphs;
     }
   return paragraphs;
}


No compiler complaint in the interface... but in the implementation I get


"Unknown type name Page."


Now if I go to the Page.h... and add


@interface Page<ObjectType> : NSObject

@end


Then go back to the category and change the category to use <ObjectType> instead of <Page> I'm good. I guess my question would be why do we need to declare a kind of type to do this. Shouldn't a NSArray category be able to just use the class name...instead of adding some unnecessary type name into the mix?

I must be making some kind of mistake. If I do:


NSArray <NSString*>*chicken = [NSArray array];
[chicken numberOfParagaphsInAllPages];


No warnings or errors, so there's no point in marking the category this way. I must be doing something wrong here.

If anyone could tell me what I'm doing wrong, that would be a good look.

Thanks!

uh...just watched the generics sections in the swift-objc interop WWDC video.....


They have a slide:


@interface NSDictionary<KeyType,ObjectType> (Lookup)

-(nullable ObjectType)objectForKey:(KeyType)aKey;


What good does that do? Categories aren't allowed to override methods....? Shouldn't marking the the dictionary, in whatever class it is being used in with the proper class be enough...


Having a hard time finding a valid example of using generics in categories of collections.

Categories on NSArray using ObjC Generics?
 
 
Q