This is a Cocoa n00b question - I have been programming GUI applications for years in other environments, but now I would like to understand what the "idiomatic Cocoa" is for the following trivialized situation:
I have a simple custom NSViewone that allows the user to draw simple shapes in it. Its implementation drawRectis as follows:
- (void)drawRect:(NSRect)rect
{
[[NSColor whiteColor] set];
NSRect bounds = [self bounds];
[NSBezierPath fillRect:bounds];
[[NSColor blackColor] set];
for (NSValue *value in shapes)
{
NSRect someRect;
[value getValue:&someRect];
[self drawShapeForRect:someRect];
}
[self drawShapeForRect:[self dragRect]];
}
You can see how simple this code is: an array instance variable shapesacts like the model the method drawRectuses to draw shapes. New ones NSRectare added to shapesevery time the user executes the mouse / drag / mouse sequence, which I also implemented in this user view. Here is my question:
"" Cocoa, ?
, ? , NSMutableArray, , , API. , , / , , . GUI , - , , - , - .
, Cocoa delegate , MyDocument ( , ) , xib. , shapeAdded:(NSRect)shape . , , , ( ) ( ) ( ), .