On Nov 30, 2009, at 12:41 AM, Kenny Leung wrote:

--------- Constants.h ---------------

extern const NSString *Suction;

--------- Constants.m ---------------

const NSString *Suction = @"Ball";

That should be:

extern NSString* const Suction;

and:

NSString* const Suction = @"Ball";


The difference is pointer-to-const-NSString vs. const-pointer-to- NSString. You want the latter for two reason. First, you don't want somebody to be able to reassign Suction. As you declared/defined it, they could.

Second, the NSString's internal contents _may_ in fact not be constant, even though the string is immutable. (For example, it could, in theory, cache an alternative encoding of its contents if it's asked for it, to make subsequent requests faster. I admit this is unlikely.) In any case, you'll get compiler warnings if you try to assign or pass a pointer-to-const-NSString where a pointer-to-NSString is expected.

Regards,
Ken

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to