Re: NSString* kMyKey = @"aKey" vs #define MYKEY @"aKey"
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