Error "Create a concrete instance!"
Asked Answered
H

1

11

I've got another problem in the same code... I'm getting this error:

initialization method -initWithCharactersNoCopy:length:freeWhenDone: cannot be sent to an abstract object of class NSString_RegEx: Create a concrete instance!

But I don't understand the error or what I should do...

edit:

NSString *pageContent = [[NSString alloc] initWithData:pageContents encoding:NSASCIIStringEncoding];
NSString_RegEx *pContent = [[NSString_RegEx alloc] initWithString: pageContent];
Highness answered 2/4, 2010 at 21:26 Comment(1)
HOw did you allocate this instance?Choi
A
16

You're seeing this because NSString is a class cluster. See Apple's docs here for a general explanation, and here for notes specifically on subclassing NSString. Basically, NSString is an abstract class with no method of storing characters, and the various -initWith… methods all return different concrete subclasses of NSString based on the method of initialization. Normally, when you're using NSString, this is completely transparent. However, if you want to subclass NSString, you have to at least implement the base methods (-length, and -characterAtIndex:) plus any init methods you want to have (plus, obviously, have a way of storing the characters of the string).

If you just want to add functionality to NSString, subclassing isn't usually necessary. First, you should check if a category, or a function operating on an NSString, or a method on a class that contains the NSString will work better. For example, see RegexKit or Google Toolbox For Mac, both of which implement regular expression support using a category on NSString.

Alterable answered 3/4, 2010 at 16:49 Comment(1)
Thanks a lot! My other problem is solved to! (A) I couldn't find something like RegexKit...Highness

© 2022 - 2024 — McMap. All rights reserved.