Im trying to add an init method in a category like this:
@interface NSError (message)
+(id)errorWithCode:(NSInteger)code message:(NSString*)message;
-(id)initWithCode:(NSInteger)code message:(NSString*)message;
@end
–
@implementation NSError (message)
+(id)errorWithCode:(NSInteger)code message:(NSString*)message;
{
return [[[[self class] alloc] initWithCode:code message:message] autorelease];
}
-(id)initWithCode:(NSInteger)code message:(NSString*)message;
{
NSMutableDictionary * userInfo = [NSMutableDictionary dictionary];
[userInfo setValue:message forKey:NSLocalizedDescriptionKey];
self = [super initWithDomain:@"some.domain" code:code userInfo:userInfo]; // problem line
return self;
}
@end
But it complais about “super” beeing of class NSObject and not responding to initWithDomain…
I tried casting super to NSError but compiler says it is not allowed.
If I run it, I get “unrecognized selector sent to…” so it’s not just a casting error.
You didn’t inherit from
NSError, you added new code to the same class. So instead ofsuperyou should probably be callingself.