我正在尝试创建一个 NSError 类别来根据状态代码生成预定义的错误。但是,每当我尝试从我的类别中创建一个 NSError 时,我都会得到一个
+[NSError errorWithDomain:code:userInfo:]: unrecognized selector sent to class 0x2b2b20
我也尝试过调用 NSError Initializer 的实例版本,但结果相同。
+(NSError*)errorOfType:(ErrorType)errorType inClassNamed:(NSString*)_nsClassName andMessage:(NSString*)_nsMessage
{
return [[[self class] alloc]initWithType:errorType inClassNamed: _nsClassName andMessage:_nsMessage];
}
#pragma mark -
#pragma mark - Init
-(id)initWithType:(ErrorType)errorType inClassNamed:(NSString*)_nsClassName andMessage:(NSString*)_nsMessage
{
NSInteger _nCode = [self codeFromErrorType:errorType];
NSDictionary *_nsUserInfo = [self localizedDescriptionForErrorType:errorType andMessage:_nsMessage];
NSLog(@"Why Does this fail? Is this Nil? %@, \n%i, \n%@", _nsClassName, _nCode, _nsUserInfo);
if ([self respondsToSelector:@selector(initWithDomain:code:userInfo:)]) {
if (self = [self initWithDomain:_nsClassName code:_nCode userInfo:_nsUserInfo]){
}
}else{
NSLog(@"NSERROR Did not create!!!");
}
return self;
}
当我运行此代码调用静态方法时,输出为:
2013-05-10 17:46:18.851 BMPassSDK-DemoApp[99692:c07] Why Does this fail? Is this Nil? Domain,
107,
{
NSLocalizedDescription = "A connection to the server could not be made. Please Try again later. ";
}
2013-05-10 17:46:18.851 BMPassSDK-DemoApp[99692:c07] NSERROR Did not create!!!
2013-05-10 17:46:18.852 BMPassSDK-DemoApp[99692:c07] +[NSError errorWithDomain:code:userInfo:]: unrecognized selector sent to class 0x2b2b20
(lldb) po 0x2b2b20
$0 = 2829088 NSError
(lldb)
有人对我所缺少的有任何建议吗?