开发者

Error "Create a concrete instance!"

开发者 https://www.devze.com 2022-12-25 06:18 出处:网络
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_Reg

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];


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消