Re: Objective-C++, class scope constants, name conflicts
Re: Objective-C++, class scope constants, name conflicts
- Subject: Re: Objective-C++, class scope constants, name conflicts
- From: Keith Ray <email@hidden>
- Date: Sun, 12 Feb 2006 10:39:06 -0800
Another way to deal with "magic numbers" in Objective C is to write
methods that return them.
@implementation Someclass
+ (int) someClassLevelNumber
{
return 5;
}
- (int) someInstanceLevelNumber
{
return 6;
}
@end
...
x = [ Someclass someClassLevelNumber ];
y = [ someInstance someInstanceLevelNumber ];
Not suitable for use as constants in array-definitions, etc., but open
for overriding in subclasses, or even refactoring to become variable
rather than constant.
On 2/11/06, Scott Ribe <email@hidden> wrote:
> > ...since you're using it in objective c++, define it inside a
> > NAMESPACE in the header
> > file.
>
> That's what I ended up doing. The discussion has brought up some other
> alternatives which I'll look at if I have a similar problem in the future,
> or am reworking things to use bindings. But for now the namespace works,
> especially since there were already associated namespaces defined for the
> data model and I didn't have to create new ones just for this one purpose.
>
> --
> Scott Ribe
> email@hidden
> http://www.killerbytes.com/
> (303) 722-0567 voice
>
>
> _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> Cocoa-dev mailing list (email@hidden)
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden
>
--
C. Keith Ray
<http://homepage.mac.com/keithray/blog/index.html>
<http://homepage.mac.com/keithray/xpminifaq.html>
<http://homepage.mac.com/keithray/resume2.html>
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden