Search code examples
categoriescappuccino

Unable to add a category to a CPArrayController (cappuccino)


I'm trying to add a method to the CPArrayController class via a category. The template for adding reverse to the CPString works fine but I'm unable to add anything to the CPArrayController. While compiling I get the error

SyntaxError: * Could not find definition for class "CPArrayController"

Here is my code:

@import <AppKit/CPArrayController.j>

    @implementation CPArrayController (Inserting)

    - (CPObject)insertAndReturn
    {
        if (![self canInsert]) return nil;
        var newObject = [self automaticallyPreparesContent] ? [self newObject] : [self _defaultNewObject];
        [self addObject:newObject];
        return newObject;
    }
    @end

Any idea why ?


Solution

  • CPArrayController ist Part of AppKit.

    So you need to import it, like :

    @import <AppKit/CPArrayController.j>
    
    @implementation CPArrayController (Inserting)
    
    - (CPObject)insertAndReturn
    {
        if (![self canInsert]) return nil;
        var newObject = [self automaticallyPreparesContent] ? [self newObject] : [self _defaultNewObject];
        [self addObject:newObject];
        return newObject;
    }
    @end