I created a subclass of NSMutableAttributedString in one of my projects to create a string that constantly changes each character to one of the colors specified in the array in init, but when I try to call the init method, I get sigabrt using the initWithString: .
RainbowString.h
initWithColors:
- (id)initStringWithColors:(NSArray *)colors withString:(NSString *)string { self = [super initWithString:string]; if(self) { [self setColors:colors]; [self cycle]; } return self; }
Even if I just call [[RainbowString alloc] initWithString:@"Hello"]; I get the same error:
* Application termination due to an uncaught exception "NSInvalidArgumentException", reason: '- [RainbowString initWithString:]: unrecognized selector sent to instance 0x166778c0'
Update
Well, therefore, to test this, I created a test subclass of NSMutableAttributedString with absolutely no content. I just created a subclass and left it open.
test.h
I ran:
[[NSMutableAttributedString alloc] initWithString:@"Hello"];
This is launched and compiled perfectly. But then I ran:
[[Test alloc] initWithString:@"Hello"];
The same mistakes. Am I not allowed to subclass NSMutableAttributedString or something else?
source share