I use this code to draw some rects in a view. This is the code:
CGContextRef myContext = [[NSGraphicsContext currentContext] graphicsPort];
CGContextSetRGBFillColor (myContext, 1, 0, 0, 1);
CGContextFillRect (myContext, CGRectMake (0, 0, 200, 100 ));
CGContextSetRGBFillColor (myContext, 0, 0, 1, .5);
CGContextFillRect (myContext, CGRectMake (0, 0, 100, 200));
When I use the code in a simple AppDelegate
, everything is okay. But, when I use it in any Document-based application (in Document.m
), I receive this error:
<Error>: CGContextSetRGBFillColor: invalid context 0x0
<Error>: CGContextFillRects: invalid context 0x0
<Error>: CGContextSetRGBFillColor: invalid context 0x0
<Error>: CGContextFillRects: invalid context 0x0
What am I missing?