What's the best way to store error messages (specially while developing with Xcode and Objective-C for Mac and iPhone):
- Creating a separate class that contains list of error code and corresponding messages
- .plist of error code and corresponding messages
- Localizable.string 开发者_StackOverflowfile with error code and corresponding messages (the application may or may not support localization)
- Other(s)
I'm sure i don't have to give a reason why anyone would want to keep all the error messages in one location. Thanks.
Your file doesn't have to be called Localizable.strings
. You can have a file called Errors.strings
. When you want to get the error description, you can use:
NSString *errCode = @"err1";
NSString *errDesc = [[NSBundle mainBundle] localizedStringForKey:errCode
value:nil
table:@"Errors"];
You could use a plist
file, however all the work is done for you with a strings
file, you don't have to write any code to parse any file or initialise some dictionary or array (no matter how easy that is anyway).
I would go for option 3. If you want to support localizations later on, you will need the .strings files anyway.
I've done something similar to this in the past, and I used something like option #2.
A file (.plist or otherwise) where an entry consists of "ErrCode Description" makes it easy to parse/search for certain errors.
精彩评论