Re: Extending NSTextStorage
Re: Extending NSTextStorage
- Subject: Re: Extending NSTextStorage
- From: Martin Wierschin <email@hidden>
- Date: Wed, 11 May 2011 14:06:17 -0700
> I try to subclass NSTextStorage and use it in text view
...
> So I try to use delegate, to handle all needed events with same functionality:
Although it might be natural to say that your MyTextStorage class "delegates" storage to an NSMutableAttributedString, it's not a good word to use here, because in Cocoa a delegate is something more specific. Normally a delegate is a weak/unretained reference to some kind of owning/controller object that customizes behavior, see:
http://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/CocoaFundamentals/CocoaDesignPatterns/CocoaDesignPatterns.html#//apple_ref/doc/uid/TP40002974-CH6-SW19
> What I need to do to extend this class ?
Your subclass (as shown) can't work because it hasn't overridden all the primitive methods. You also need to implement attributesAtIndex:effectiveRange:. See:
http://developer.apple.com/library/mac/documentation/cocoa/Conceptual/TextStorageLayer/Tasks/Subclassing.html#//apple_ref/doc/uid/20000926-CJBBIAAF
However, from your error:
> An uncaught exception was raised
> *** NSRunStorage, _NSBlockNumberForIndex(): index (18446744073709551615) beyond array bounds (0)
> *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** NSRunStorage, _NSBlockNumberForIndex(): index (18446744073709551615) beyond array bounds (0)'
That looks like an exception raised by the layout manager. You might have other problems with your code. I'd use a stock NSTextStorage first and make sure everything is working.
~Martin
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden