• 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: Best way to Define Project Wide Static Strings?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Best way to Define Project Wide Static Strings?


  • Subject: Re: Best way to Define Project Wide Static Strings?
  • From: Graham Cox <email@hidden>
  • Date: Thu, 8 Apr 2010 23:32:04 +1000

On 08/04/2010, at 9:23 PM, Dave wrote:

> I have a number of Constant Strings that are project wide

> static NSString	kString1 = @"some string";


If they are project-wide they should not be 'static', which has the scope only of the file that they are declared in. On the other hand if that's what you want, the best (and only) place for them is the file where they're used.

> What is a good way to handle this? Is there a preferred method?


Constant strings have to exist somewhere, so they may as well exist in the file where they are most relevant. If you need to refer to them elsewhere, in the header for that file you can use 'extern'. Include that header wherever you need the string.

e.g.

// foo.h

extern NSString* kString1;

// foo.m

NSString* kString1 = @"bar";


Dunno if this is the preferred method but it's what I do. What I don't generally do is centralise all my strings in one file, on the basis that if I reuse a class in another project, any strings it uses go with it.

--Graham


_______________________________________________

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: Best way to Define Project Wide Static Strings?
      • From: Filip van der Meeren <email@hidden>
References: 
 >Best way to Define Project Wide Static Strings? (From: Dave <email@hidden>)

  • Prev by Date: Re: "Toll free" bridge from NSAttributedString * to CFAttributedStringRef
  • Next by Date: Re: copy/paste in modal window
  • Previous by thread: Best way to Define Project Wide Static Strings?
  • Next by thread: Re: Best way to Define Project Wide Static Strings?
  • Index(es):
    • Date
    • Thread