Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error "Create a concrete instance!"

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];
like image 988
dododedodonl Avatar asked Apr 02 '10 21:04

dododedodonl


1 Answers

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.

like image 114
Boaz Stuller Avatar answered Oct 10 '22 21:10

Boaz Stuller