I am creating my first Mac app, a text editor. It is document-based, and the Document.xib has an nstextview. I have made the Document class the delegate of the textview. I am implementing the method:
-(void)textViewDidChangeSelection:(NSNotification *)notification
{
NSRange range=self.textView.selectedRange;
NSLog(@" %@ ",[[self.textView textStorage] attributesAtIndex: range.location
effectiveRange: &range]);
I will be using the method call that is inside NSLog to get the attributes of selected text and update from that notification method the Underline button(pressed or not). The problem is that when the app runs and I press a key an exception is raised: an uncaught exception was raised
*** -[NSConcreteTextStorage attributesAtIndex:effectiveRange:]: Range or index
out of bounds
I tried debugging by a @try: @catch: block and it seems that the method as above always throws that exception. If I replace:
range.location
with
(range.location-1)
it throws that exception only when the cursor is at index 0.
Does anyone know what is happening?