Re: Using #define a good way for String constants, like enums for NSIntegers?
Re: Using #define a good way for String constants, like enums for NSIntegers?
- Subject: Re: Using #define a good way for String constants, like enums for NSIntegers?
- From: Jerry Krinock <email@hidden>
- Date: Tue, 09 Aug 2011 05:58:28 -0700
On 2011 Aug 09, at 03:47, Devraj Mukherjee wrote:
> Are Strings defined using #define good enough as String constants?
It will work, but is considered to be bad form, I think because it could bloat your code some trivial amount by having a constant defined multiple times, if the compiler does not recognize and combine them during optimization. Or maybe just because THIS_LOOKS_UGLY.
> Or Should I be doing this another way?
This is how it's usually done:
In a .m, .c or .cpp file,
NSString* const constEntityNameLog = @"Log_entity" ;
and if you need to use this constant in other files, add, in the counterpart header file,
extern NSString* const constEntityNameLog ;
_______________________________________________
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