NSError - Custom localised messages

NSError can be customised to deliver localized messages to the user. This is meant to show meaningful messages based on situations where and when error happens.

1. Create a strings file.
As iOS supports localization, we need to add "strings" file to our project and add the error messages.

"99" = "Exception occurred"
"100" = "Login Successful.";
"101" = "Logout failed";
"102" = "Unable to connect server";
"103" = "Invalid input data";

2. Add two macro that would help to fetch the localized messages.
#define ERROR_KEY(code)                    [NSString stringWithFormat:@"%d", code]
#define ERROR_LOCALIZED_DESCRIPTION(code)  NSLocalizedStringFromTable(ERROR_KEY(code), @"Error", nil)

// "Error" is the strings file name.

Comments

Popular posts from this blog

Integrating ZXing QR Code reader in iPhone / iOS applications

Multiple line of text in UIPickerView

Connect Samsung devices to Kies on Mac