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?
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
NSCocoaErrorDomainis 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.