Re: Defining a constant as private
Re: Defining a constant as private
- Subject: Re: Defining a constant as private
- From: "Dennis C. De Mars" <email@hidden>
- Date: Wed, 16 Jun 2004 23:38:56 -0700
On Jun 16, 2004, at 6:36 AM, Joakim Danielson wrote:
On 2004-06-16, at 13.44, Wade Tregaskis wrote:
How do I define a constant to be private to a class, and specially a
string constant?
ObjC isn't big on things being private... the only reliable way to do
this is to #define your value, but that's not a good idea for
non-immediate (i.e. non-integer, basically) values.
The best way, I guess, is to just define the constant in your
implementation file, so it's not visible to the outside world. Leave
it undocumented, or if you must document it make it quite explicit
that it shouldn't be used (provide a good reason, too). 3rd party
developers could always declare it as extern manually, but that's
probably a danger you'll have to accept... they could always modify
your source to expose it anyway, if all else fails. :)
Wade Tregaskis (aim: wadetregaskis)
-- Sed quis custodiet ipsos custodes?
If I understand you correctly I can't make the constant truly private
and therefore I will have to make sure that the name of the constant
is unique even if I just declare it in my implementation file. Is this
correct?
Ummm... I don't see why you couldn't define, in your implementation
file:
static NSString* myConstString = @"whatever";
or stick const in front of it also, but the main point is, the
identifier "myConstString" will then be private to that file, even if
another file defines an extern variable with the same name.
- Dennis D.
_______________________________________________
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.