Reputation: 1132
I'm creating a list of error codes as so
enum{
firstErrorCode = 1,
secondErrorCode = 2,
};
I would like to create an error domain-type concept for a custom error class (subclass of NSObject) I'm writing.
Is there any way I could associate this enumeration with a string name? For instance MyErrorDomain?
Upvotes: 0
Views: 187
Reputation: 96323
There's no way to tie an enumeration to an error domain name. If you look in the Cocoa errors headers (FoundationErrors.h and CoreDataErrors.h), you'll see that no connection with NSCocoaErrorDomain
is declared to the compiler; the connection is all in people's heads, expressed only in documentation.
So it is with your own error domain: You document, in comments and/or separate documentation, that these error codes go with that domain, and that is the maximal extent to which you can connect them.
Upvotes: 1
Reputation: 14304
I would create a STATIC function in that class that handles this with a simple switch-case. You could ask what type you are dealing with and return the associated NSString.
Upvotes: 0