• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Defining and using constants in Objective C
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

  • Follow-Ups:
    • Re: Defining and using constants in Objective C
      • From: Ken Thomases <email@hidden>
References: 
 >Defining and using constants in Objective C (From: Tharindu Madushanka <email@hidden>)

  • Prev by Date: Re: How to draw text to bitmap (array) with pre 10.5 libs
  • Next by Date: Re: Core Data and +[NSExpression expressionForFunction:...]
  • Previous by thread: Re: Defining and using constants in Objective C
  • Next by thread: Re: Defining and using constants in Objective C
  • Index(es):
    • Date
    • Thread