Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: String constants and how to do them



On Mar 25, 2004, at 08:45, Kevin Ballard wrote:

> I forget where I read this (perhaps it was Aaron Hillegass's book, but
> I forget), but I read somewhere that in general it's a better idea to
> use global strings set to a constant string rather than using #define,
> as in
>
> NSString *myPref = @"My Preference";
>
> instead of
>
> #define myPref @"My Preference"
>
> Is there a reason for this? Is this even true? What do you guys use?

Generally, it's best to avoid using the preprocessor wherever
possible. There are many subtle problems that can arise when using
preprocessor macros. In this case, naming conflicts can cause very
unintuitive problems (i.e. what if someone has a method/local
variable/function named "myPref"?).


--
Clark S. Cox III
email@hidden
http://homepage.mac.com/clarkcox3/
http://homepage.mac.com/clarkcox3/blog/B1196589870/index.html

[demime 0.98b removed an attachment of type application/pkcs7-signature which had a name of smime.p7s]
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.


References: 
 >String constants and how to do them (From: Kevin Ballard <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.