• 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: Keys of the kingdom
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Keys of the kingdom


  • Subject: Re: Keys of the kingdom
  • From: Shawn Erickson <email@hidden>
  • Date: Sat, 22 Apr 2006 16:05:08 -0700


On Apr 22, 2006, at 3:49 PM, Boyd Collier wrote:


I had the same question as Kevin, but my c is a bit rusty. Ondra, could you be
more specific re using extern const in this context?

In what context exactly?

If you have code like this...

[dictionary setObject:object forKey:@"My Key"];
...
[dictionary objectForKey:@"My Key"];

...it makes sense to centrally define the string constant so you only have to track and modify it in one location.

You can do that by using macros...

#define MY_KEY @"My Key"

...but a better way IMHO is to use string constants (also what Apple usually does). To do that you would...

---- SomeHeaderFile.h ----

extern NSString* const kMyKey;

---- SomeCodeFile.m (or .mm) ----

NSString* const kMyKey = @"My Key";

---- Some other code ----

[dictionary setObject:object forKey: kMyKey];
...
[dictionary objectForKey: kMyKey];

What "NSString* const" says is that the "kMyKey" variable is an immutable (constant) pointer to an NSString instance and NSString is immutable by definition and also happens to be a constant string which cannot be deallocated.

-Shawn
_______________________________________________
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: 
 >Keys of the kingdom (From: Kevin Bracey <email@hidden>)
 >Re: Keys of the kingdom (From: Ondra Cada <email@hidden>)
 >Re: Keys of the kingdom (From: Boyd Collier <email@hidden>)

  • Prev by Date: Re: Keys of the kingdom
  • Next by Date: Re: Core Data Merged Models
  • Previous by thread: Re: Keys of the kingdom - THANKS!
  • Next by thread: how do I drag into tableViews?
  • Index(es):
    • Date
    • Thread