Re: Creating a console view
Re: Creating a console view
- Subject: Re: Creating a console view
- From: Jens Alfke <email@hidden>
- Date: Tue, 16 Mar 2010 18:55:02 -0700
On Mar 16, 2010, at 6:19 PM, Rick Mann wrote:
> I'm currently using an NSTextView, and calling the following to append text:
>
> NSString* existingText = self.output.string;
> NSRange r = NSMakeRange(existingText.length, 0);
> [self.output replaceCharactersInRange: r withString: s];
That line shouldn’t compile, or rather, you should get a warning about it, since NSString doesn’t respond to that message. And you shouldn’t leave warnings like that in your code, since they’re usually telling you something important. In this case, NSTextView’s -string property has a return type of NSString, implying that the object is immutable. It happens that the implementation returns an NSMutableString, which is why your code doesn’t bomb at runtime, but NSTextView is not expecting you to go mutating its internal storage behind its back, which is why it doesn’t know to redisplay itself.
What you should do instead is use the -textStorage property (which does return a mutable attributed string), and bracket your changes with -beginEditing and -endEditing.
—Jens_______________________________________________
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