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

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


  • Subject: NSString* kMyKey = @"aKey" vs #define MYKEY @"aKey"
  • From: Memo Akten <email@hidden>
  • Date: Fri, 3 Apr 2009 22:41:25 +0100

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: Nate Weaver <email@hidden>
  • Prev by Date: Re: How to animate the drawing of UIImages inside a drawRect: method of a UIView?
  • Next by Date: Re: Best Practice for reading a string with NSScanner
  • Previous by thread: Re: Reading cab into object
  • Next by thread: Re: NSString* kMyKey = @"aKey" vs #define MYKEY @"aKey"
  • Index(es):
    • Date
    • Thread