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

Re: Newbie question: constants


  • Subject: Re: Newbie question: constants
  • From: Tim Hart <email@hidden>
  • Date: Fri, 19 Nov 2004 01:15:28 -0600


On Nov 18, 2004, at 11:34 PM, Wade Tregaskis wrote:

The scenario I was referring to was using a mutable object - e.g. NSNumber as you suggest - as a constant. I wasn't picking on your method in particular, just stating it only works for truly immutable objects.

Just for clarification - there's a little more going on than just mutable/immutable objects. You're right in saying that life gets impossible if you try to define a global constant using a mutable object - it's a contradiction.


But NSNumber is, in fact, immutable. The problem there is that there is no way to define it's value at compile time. You can't do this:

    NSNumber* const kMyNumber = [ NSNumber numberWithInt:34];

because it's an executable statement, and as such, must reside in a function or method somewhere. And a const variable has to be initialized when it is declared. Too bad there is no '@34' construct. For newbies - look at the definition of the +load method on NSObject for hints to one possible solution to this problem. Other threads in the past cover the good and bad of this method of defining global constants that are not strings.

I don't think we're in disagreement at all Wade. I'm trying to clarify things for newbies and others who might stumble across this thread in a mamasam search later...


Wade Tregaskis (AIM, Yahoo & Skype: wadetregaskis, ICQ: 40056898, MSN & email: email@hidden, Jabber: email@hidden)
-- Sed quis custodiet ipsos custodes?



_______________________________________________ Do not post admin requests to the list. They will be ignored. Cocoa-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
References: 
 >Newbie question: constants (From: "Colin O'Connor" <email@hidden>)
 >Re: Newbie question: constants (From: Wade Tregaskis <email@hidden>)
 >Re: Newbie question: constants (From: Tim Hart <email@hidden>)
 >Re: Newbie question: constants (From: Wade Tregaskis <email@hidden>)
 >Re: Newbie question: constants (From: Tim Hart <email@hidden>)
 >Re: Newbie question: constants (From: Wade Tregaskis <email@hidden>)

  • Prev by Date: Re: Newbie question: constants
  • Next by Date: Fastest way to push strings to the screen in an NSView?
  • Previous by thread: Re: Newbie question: constants
  • Next by thread: Setting up multiple Dependent Keys
  • Index(es):
    • Date
    • Thread