• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Why is "set" a class method of NSColor?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Why is "set" a class method of NSColor?


  • Subject: Why is "set" a class method of NSColor?
  • From: Jack Boyce <email@hidden>
  • Date: Thu, 3 Dec 2009 18:46:41 -0800

I'm learning Cocoa, trying to understand certain "magical" features where it
isn't obvious how things work under the hood.  (KVO and isa-swizzling is
another prime example.)

Can someone kindly explain, or point me to an explanation for, what's really
happening with:
    [[NSColor blueColor] set];

In other APIs one commonly sees methods on the target view for setting
things like pen color and transformations.  I.e., why is it not:
     [myView setPenColor:[NSColor blueColor]];

In particular, how does the NSColor object know which NSView you're talking
about when you send it the 'set' message?  My current hypothesis is that
information like pen color is recorded somehow in the [NSGraphicsContext
currentContext] object for the current thread, but I can't confirm this in
the docs.  This would imply Cocoa is doing work behind the scenes to set up
the NSGraphicsContext before it calls your view's drawFrame: method, and
then cleaning up when you return.  Is the idea then that one should only
draw within the drawFrame: method of NSView, and only from the main thread
(when Cocoa calls it)?  I.e., there is no multi-threaded drawing in Cocoa?

Thanks,
Jack
_______________________________________________

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

  • Follow-Ups:
    • Re: Why is "set" a class method of NSColor?
      • From: Jack Boyce <email@hidden>
  • Prev by Date: Fwd: applicationShouldTerminate problem
  • Next by Date: Re: Why is "set" a class method of NSColor?
  • Previous by thread: Re: applicationShouldTerminate problem
  • Next by thread: Re: Why is "set" a class method of NSColor?
  • Index(es):
    • Date
    • Thread