• 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
Re: Newbie question - is where Obj-C analog for a C++ static data
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Newbie question - is where Obj-C analog for a C++ static data


  • Subject: Re: Newbie question - is where Obj-C analog for a C++ static data
  • From: matt neuburg <email@hidden>
  • Date: Thu, 11 Sep 2003 08:59:17 -0700

On Wed, 10 Sep 2003 11:23:17 +0400, Rustam Muginov <email@hidden> said:
>Hello all.
>I have a document-based applications, with several windows where different
>objects are drawn.
>I need to draw them with the different colors, depending on the object
>"type" or "kind".
>So I created the NSDictionary, with the colors as objects and object types
>as the keys.
>
>The questions is - how could I optimize my code and not the build such
>colors dictionary for every WindowController (or for every document)?
>In C++, I could declare the static data member for the class, init it with
>NULL value, and then check it from the instance method, building the color
>list if its not already build.
>In Cocoa, I could probably define the "standalone" global variable and use
>it for the same purposes, but I feel this is not very "cocoa-ish"
>
>How should I implement "shared" object, which will be inited once and then
>used by many instances?

In exactly the same way as in C++ - use a class static. See the ClassClusters.html document on your hard drive for an example. m.

--------
matt neuburg, phd = email@hidden, http://www.tidbits.com/matt/
pantes anthropoi tou eidenai oregontai phusei
Subscribe to TidBITS! It's free and smart. http://www.tidbits.com/
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Prev by Date: Cocoa menus and Carbon menus
  • Next by Date: Re: JPEG and 72 dpi revisited...
  • Previous by thread: Cocoa menus and Carbon menus
  • Next by thread: Notification Issue
  • Index(es):
    • Date
    • Thread