views:

91

answers:

3

What's the best way to store error messages (specially while developing with Xcode and Objective-C for Mac and iPhone):

  1. Creating a separate class that contains list of error code and corresponding messages
  2. .plist of error code and corresponding messages
  3. Localizable.string file with error code and corresponding messages (the application may or may not support localization)
  4. 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.

+1  A: 

I would go for option 3. If you want to support localizations later on, you will need the .strings files anyway.

Diederik Hoogenboom
+1  A: 

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.

alesplin
+1  A: 

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).

dreamlax