Re: Defining and using constants in Objective C
Re: Defining and using constants in Objective C
- Subject: Re: Defining and using constants in Objective C
- From: Kenny Leung <email@hidden>
- Date: Sun, 29 Nov 2009 22:41:49 -0800
Hi Tharindu.
I would create two files: Constants.h and Constants.m. Just like all C code, you put your declarations in the .h and the definitions in the .m. They are going to be very similar, except the .m defines the values, so it only happens once. This is very important if you want to be able to compare NSString constants using pointer equality. You then have all of your other code import Constants.h
--------- Constants.h ---------------
extern const int Foo;
extern const float Bar;
extern const NSString *Suction;
--------- Constants.m ---------------
const int Foo = 42;
const float Bar = 4.2;
const NSString *Suction = @"Ball";
-Kenny
On Nov 29, 2009, at 9:30 AM, Tharindu Madushanka wrote:
> Hi
>
> When defining constants can I keep all important constants in one file and
> use it all over the application, rather defining same constant in several .m
> files. This might be a basic question, but just could not figure out how to
> do this.
>
> Thank you
> Tharindu Madushanka
> _______________________________________________
>
> 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
_______________________________________________
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