views:

140

answers:

1

Hey All,

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];
+3  A: 

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.

Boaz Stuller
Thanks a lot! My other problem is solved to! (A) I couldn't find something like RegexKit...
dododedodonl