• 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: Class variable?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Class variable?


  • Subject: Re: Class variable?
  • From: John Randolph <email@hidden>
  • Date: Fri, 6 Feb 2004 13:39:05 -0800

On Feb 6, 2004, at 12:52 PM, Randall Meadows wrote:

[Man, I hope this isn't a stoopit question...]

The only stupid question is the one you don't ask.

Is there a way in Cocoa to define a class variable that is shared among all instances of that class, analogous to a +method? How?

Remembering that Objective-C is a superset of C...

The usual way we do this kind of thing in Cocoa programs is to use a static variable in the .m file, and provide an accessor for it:

static float myClassVar

@implementation MyClass

+ (float) classVarValue { return myClassVar; }
+ (void) setClassVarValue:(float) aValue { myClassVar = aValue; }

@end

..and of course, any method in that file will also be able to see myClassVar directly.

Other implementations I've seen did things like keep a dictionary of dictionaries, where the top level dictionary's keys were class names.

[PS-What are the feelings about cross-posting to cocoa-dev and macosx-dev?

Doesn't bug me much, but I've seen a few complaints.

-jcr


John C. Randolph <email@hidden> (408) 974-8819
Sr. Cocoa Software Engineer,
Apple Worldwide Developer Relations
http://developer.apple.com/cocoa/index.html
_______________________________________________
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.

References: 
 >Class variable? (From: Randall Meadows <email@hidden>)

  • Prev by Date: Clipboard in Background Applications
  • Next by Date: Re: malloc in obj-c/cocoa
  • Previous by thread: Re: Class variable?
  • Next by thread: Re: Class variable?
  • Index(es):
    • Date
    • Thread