forked from jerrykrinock/CategoriesObjC
/
NSError+MyDomain.m
45 lines (37 loc) · 1.46 KB
/
NSError+MyDomain.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#import "NSError+MyDomain.h"
#import "NSError+InfoAccess.h"
@implementation NSError (MyDomain)
+ (NSError*)errorWithLocalizedDescription:(NSString*)localizedDescription
code:(NSInteger)code
prettyFunction:(const char*)prettyFunction {
NSDictionary* userInfo = nil ;
if (localizedDescription) {
NSString* const CFBundleVersionKey = @"CFBundleVersion" ;
userInfo = [NSDictionary dictionaryWithObjectsAndKeys:
localizedDescription, NSLocalizedDescriptionKey,
[[NSBundle mainBundle] objectForInfoDictionaryKey:CFBundleVersionKey], CFBundleVersionKey,
// The following gets added in -[SSYAlert support:]. It would be nice to do it here instead.
// But then I'd have to #import SSYSystemDescriber into any project using this file.
//[SSYSystemDescriber softwareVersionAndArchitecture], @"System Description",
nil] ;
}
NSError* error = [NSError errorWithDomain:[self myDomain]
code:code
userInfo:userInfo] ;
error = [error errorByAddingPrettyFunction:prettyFunction] ;
error = [error errorByAddingTimestampNow] ;
return error ;
}
+ (NSString*)myDomain {
NSString* domain = [[NSBundle mainBundle] bundleIdentifier] ;
// Background/daemon/helper/tools will usually not have a bundle...
if (!domain) {
NSString* path = [[[NSProcessInfo processInfo] arguments] objectAtIndex:0] ;
domain = [path lastPathComponent] ;
}
if (!domain) {
domain = @"UnknownErrorDomain" ;
}
return domain ;
}
@end