• 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 a constant as private
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Defining a constant as private


  • Subject: Re: Defining a constant as private
  • From: Prachi Gauriar <email@hidden>
  • Date: Wed, 16 Jun 2004 13:00:44 -0500

On Jun 16, 2004, at 8:46 AM, Joakim Danielson wrote:

On 2004-06-16, at 14.16, Steve Checkoway wrote:

On Jun 16, 2004, at 5:01 AM, j o a r wrote:

On 2004-06-16, at 13.34, Joakim Danielson wrote:

How do I define a constant to be private to a class, and specially a
string constant?

Something like this in the implementation file of the class:

NSString * const myString = @"SomeStringValue";

That creates a constant NSString object. To create a string constant, try:
const char *const myString = "SomeStringValue";

Or even better, to ensure it is not externed from somewhere else:
static const char *const myString = "SomeStringValue";

What is the advantage of using a string constant compared to a constant NSString object if I'm using the constant when working with NSMutableString objects? In the class I'm writing right now I'm using the constant to append it to another string with something like this:

[myMutableString appendString:myConstantString] or for a string constant [myMutableString appendString:[stringWithCString:myConstantString]]

Another option is to just have a "private" class method that returns this constant string, i.e.

+ (NSString *)JD_myConstantString
{
return @"A String";
}

-Prachi
_______________________________________________
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: 
 >Defining a constant as private (From: Joakim Danielson <email@hidden>)
 >Re: Defining a constant as private (From: j o a r <email@hidden>)
 >Re: Defining a constant as private (From: Steve Checkoway <email@hidden>)
 >Re: Defining a constant as private (From: Joakim Danielson <email@hidden>)

  • Prev by Date: Strange application behavior with distributed notification center
  • Next by Date: Fwd: Scrolling List of Thumbnails?
  • Previous by thread: Re: Defining a constant as private
  • Next by thread: Re: Defining a constant as private
  • Index(es):
    • Date
    • Thread