Got the idea. Thanks Adam
2005/08/11 v 19:32, YL:
> I defined the following as a consistent convention for
> my business objects' status (the mapping here is quite arbitrary, i
> don't care:-):
>
> typedef enum _EObjectStatus {
> STATUS_Pending = -5,
> STATUS_Incomplete = -4,
> STATUS_Expired = -3,
> STATUS_Disabled = -2,
> STATUS_Denied = -1,
> STATUS_Active = 1,
> STATUS_Complete = 2,
> STATUS_Reserved = 3,
> STATUS_Paid = 4,
> STATUS_Confirmed = 5,
> } EObjectStatus;
>
> It works quite handy but sometimes i need to display the status
> valueName
> for a runtime status value.
> Of course i can define a dictionary to find out value name from
> value, but
> is there a better solution?
> (without duplicated mapping definition?)
Names of enums are not preserved after compiling the code (unless you
have debugging information enabled) and therefore aren't accessible.
You can use a different solution than enums, for example statically
allocated NSStrings, which are quite common in Cocoa:
NSString * const STATUS_Pending = @"STATUS_Pending";
NSString * const STATUS_Incomplete = @"STATUS_Incomplete";
It's possible to create a custom type and avoid the mapping with a
macro (although I would rather avoid macros like this):
typedef NSString * const EObjectStatus;
#define DefineEObjectStatus(name) EObjectStatus (name) = @#name;
DefineEObjectStatus(STATUS_Pending);
DefineEObjectStatus(STATUS_Incomplete);
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Objc-language mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/objc-language/email@hidden
This email sent to email@hidden