On Mar 16, 2010, at 18:55:02, Jens Alfke wrote: > > 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.
Jens, There's no warning because there's no difference between NSString* existingText = self.output.string; and NSString* existingText = [self.output string]; even without a declared property. I prefer the former style. You'll not that I don't actually do anything with the string other than measure its length. Moreover, the return type is NSString*, so using it in this manner is perfectly valid. (I couldn't see any other way to get a range representing the end of the buffer. Nor is there an "append" operation.) But now I see that NSTextStorage is a mutable string I can append to. Thanks! > 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 (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com