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
@endIf 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
@endThen 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?