2

I am trying to add this category to CPView but XCodeCapp gives an error and I get unrecognized selector sent to instance error when I try to use this method.

@import <AppKit/CPView.j>

@implementation CPView (Custom)

- (void) addSomething
{
    var bounds = [self bounds];
    var context = [[CPGraphicsContext currentContext] graphicsPort];

    CGContextSetFillColor(context, [CPColor blueColor]);
    CGContextFillRect(context, CGRectMake(100,100,100,100));
}

@end

The syntax is correct as far as I can tell, the file name I am using is CPView_Custom.j

EDIT

I am also using IB to connect a CPView ivar to a custom view in the XIB/NIB file. Not sure if this makes a difference or not.

Andrew Lauer Barinov
  • 5,694
  • 10
  • 59
  • 83
  • `@import "CPView_Custom.j"` at the top of AppController.j – Andrew Lauer Barinov Mar 15 '12 at 00:32
  • Looks fine to me. Try to move the code to the file where you're using it. If it works then the problem would be import related. – Alexander Ljungberg Mar 15 '12 at 00:36
  • @AlexanderLjungberg I am using IB as well, might be the source of the errors (just edited my question). – Andrew Lauer Barinov Mar 15 '12 at 00:37
  • I did try to put the code inside of AppController.j and XCodeCapp gave an error when processing that file. So I have a feeling there might be IB related issues here. – Andrew Lauer Barinov Mar 15 '12 at 00:39
  • I've seen XcodeCapp come up with errors at unexpected times. I ran your code through the Objective-J compiler and it compiled fine. You might want to try to see if it works in a non XIB test app. – Alexander Ljungberg Mar 15 '12 at 00:44
  • I did give it a try in a non XIB app and I think the issue is with the way I am setting up my context for drawing. Definitely not category syntax. Thanks for your help! – Andrew Lauer Barinov Mar 15 '12 at 03:21
  • You can't draw from random methods. The only way the above will work is if it is called from within drawRect:, or as long as some other drawing context has focus. Sorry if you were already using it this way, just thought that might be the problem. – Francisco Ryan Tolmasky I Mar 30 '12 at 02:10

1 Answers1

1

XCodeCapp will always throw errors regarding Categories because the objj CLI cannot understand them as a single file.

You should ignore your categories by adding some entries in .xcodecapp-ignore.