Skip navigation.
 
mlRe: Simple question - Subclassing NSView
FROM : I. Savant
DATE : Thu Jun 12 19:39:16 2008

>  I have recently started programming on Mac using Objective-C and Cocoa. I am coming from C++/C# world.


  Recant, heretic! ;-)

>  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 all seriousness, you'll need to read the Cocoa Drawing Guide. The
answer to this quesiton is found there. NSColor's -set method tells
the current drawing context to use that color as the current drawing
color. All drawing actions will happen with that color because it's
set as the current 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?


  Using brackets means you're sending an object a message:
[someObject message];

  As you might guess, NSRectFill() is a standard c function.
Obviously, the signature gives you a good clue. Again, this applies to
the current graphics context (which knows what view currently has
focus, and therefore its bounds).

--
I.S.

Related mailsAuthorDate
mlSimple question - Subclassing NSView Vikas Jun 12, 19:26
mlRe: Simple question - Subclassing NSView Randall Meadows Jun 12, 19:31
mlRe: Simple question - Subclassing NSView Hamish Allan Jun 12, 19:33
mlRe: Simple question - Subclassing NSView Shawn Erickson Jun 12, 19:36
mlRe: Simple question - Subclassing NSView I. Savant Jun 12, 19:39
mlRe: Simple question - Subclassing NSView Vikas Jun 12, 19:54
mlRe: Simple question - Subclassing NSView Hamish Allan Jun 12, 20:14
mlRe: Simple question - Subclassing NSView I. Savant Jun 12, 20:20
mlRe: Simple question - Subclassing NSView Mike Abdullah Jun 12, 20:26
mlRe: Simple question - Subclassing NSView Kyle Sluder Jun 12, 20:28
mlRe: Simple question - Subclassing NSView Jens Alfke Jun 12, 20:33
mlRe: Simple question - Subclassing NSView Andy Lee Jun 12, 20:45