Last active
December 19, 2015 02:38
-
-
Save sebk/5884099 to your computer and use it in GitHub Desktop.
NSError category to create a localized NSError instance. Created by Jan Rose.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <Foundation/Foundation.h> | |
@interface NSError(LocalizedError) | |
/** | |
Utility method to create a localized NSError with the given error-domain, error-code and description text. | |
*/ | |
+ (NSError*)localizedErrorWithDomain:(NSString*)domain code:(NSInteger)code andDescription:(NSString*)description; | |
@end | |
#import "NSError+LocalizedError.h" | |
@implementation NSError (LocalizedError) | |
+ (NSError*)localizedErrorWithDomain:(NSString*)domain code:(NSInteger)code andDescription:(NSString*)description | |
{ | |
NSMutableArray* objArray = [NSMutableArray arrayWithCapacity:1]; | |
NSMutableArray* keyArray = [NSMutableArray arrayWithCapacity:1]; | |
[objArray addObject:description]; | |
[keyArray addObject:NSLocalizedDescriptionKey]; | |
NSDictionary *eDict = [NSDictionary dictionaryWithObjects:objArray | |
forKeys:keyArray]; | |
return [NSError errorWithDomain: domain | |
code: code | |
userInfo: eDict]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment