I'm trying out drawing in Objective-C with NSRect, but all the examples I find online result in a warning in the output log. It does draw on the View, but I would like to see that there are no issues reported by the debugger :).
I read some things about that the stuff you draw explicitly has to be inside a "context", but all the articles I find are way above my level at the moment.
Here's my code:
- (void)drawRect:(NSRect)rect
{
NSColor *white = [NSColor whiteColor];
NSColor *blue = [NSColor blueColor];
[white set];
NSRectFill([self bounds]);
rect = NSMakeRect(100, 100, 50, 50);
[blue set];
NSRectFill(rect);
}
I get these errors:
Jul 2 16:10:49 localhost X[27220] : CGContextSetFillColorWithColor: invalid context 0x0
Jul 2 16:10:49 localhost X[27220] : CGContextSetStrokeColorWithColor: invalid context 0x0
Jul 2 16:10:49 localhost X[27220] : CGContextSetFillColorWithColor: invalid context 0x0
Jul 2 16:10:49 localhost X[27220] : CGContextSetStrokeColorWithColor: invalid context 0x0
Jul 2 16:10:49 localhost X[27220] : CGContextGetCompositeOperation: invalid context 0x0
Jul 2 16:10:49 localhost X[27220] : CGContextSetCompositeOperation: invalid context 0x0
Jul 2 16:10:49 localhost X[27220] : CGContextFillRects: invalid context 0x0
Jul 2 16:10:49 localhost X[27220] : CGContextSetCompositeOperation: invalid context 0x0
Most articles talked about using "NSGraphicsContext", but all were theoretical and I couldn't find an example of how to get that to work.
I hope someone can help :)