Re: Simple question - Subclassing NSView
Re: Simple question - Subclassing NSView
- Subject: Re: Simple question - Subclassing NSView
- From: Randall Meadows <email@hidden>
- Date: Thu, 12 Jun 2008 10:31:52 -0700
On Jun 12, 2008, at 10:26 AM, Vikas wrote:
I have recently started programming on Mac using Objective-C and
Cocoa. I am coming from C++/C# world. So, its a fairly basic
question. Please help me understand the following code:
@implementation MyView /*MyView inherits from NSView */
-(void)drawRect: (NSRect)aRect {
[[NSColor blackColor] set];
NSRectFill( [self bounds] );
}
In first line, I was expecting something like [self setColor:
[NSColor blackColor]]; (similar to this.color =
NSColor.blackColor; in C#/C++)
how NSColor object knows about where to set the color?
In second line, NSRectFill(), I was expecting it to be called using
square bracket [] notation. Again how this function knows where to
fill the rectangle? There is no reference of NSView passed into the
function?
Well, as the docs state, "Sets the color of subsequent drawing to the
color that the receiver represents." So, it sets that as the current
drawing color in the current graphics context, and whatever gets
subsequently drawn in that context will be done in that color.
Lastly what are the rules of using () verses []?
() follows same rules as C; you use [] when sending messages to
Objective-C objects and classes.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden