• 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: NSString* kMyKey = @"aKey" vs #define MYKEY @"aKey"
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSString* kMyKey = @"aKey" vs #define MYKEY @"aKey"


  • Subject: Re: NSString* kMyKey = @"aKey" vs #define MYKEY @"aKey"
  • From: Nate Weaver <email@hidden>
  • Date: Fri, 3 Apr 2009 17:15:55 -0500

IIRC they're optimized to point to the same memory location (I wasn't sure, so I tested and confirmed).

I usually do:

NSString * const kConstantNameHere = @"foo";

That's what I've seen in Apple headers (with an extern at the beginning and no assignment in said headers, of course).

On Apr 3, 2009, at 4:41 PM, Memo Akten wrote:

I was wondering if there is much difference between:

NSString* kMyKey = @"aKey";

// and then throughout the application:
[myDictionary setObject:xxx forKey:kMyKey];
[myDictionary objectForKey: kMyKey];



vs

#define MYKEY @"aKey"

// and then throughout the application:
[myDictionary setObject:xxx forKey: MYKEY];
[myDictionary objectForKey: MYKEY];


The docs say the strings created with the @ construct are created at compile time. Does that mean potentially if we use the define 50 times, there are 50 NSStrings with identical content created at compile time? Or does the compiler optimize that as well?

_______________________________________________

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: NSString* kMyKey = @"aKey" vs #define MYKEY @"aKey"
      • From: Andrew Farmer <email@hidden>
    • Re: NSString* kMyKey = @"aKey" vs #define MYKEY @"aKey"
      • From: Quincey Morris <email@hidden>
References: 
 >NSString* kMyKey = @"aKey" vs #define MYKEY @"aKey" (From: Memo Akten <email@hidden>)

  • Prev by Date: Re: user access privileges to plist in /library/preferences
  • Next by Date: Re: NSDate with Format?
  • Previous by thread: NSString* kMyKey = @"aKey" vs #define MYKEY @"aKey"
  • Next by thread: Re: NSString* kMyKey = @"aKey" vs #define MYKEY @"aKey"
  • Index(es):
    • Date
    • Thread