• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Creating a console view
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

  • Follow-Ups:
    • Re: Creating a console view
      • From: Rick Mann <email@hidden>
References: 
 >Creating a console view (From: Rick Mann <email@hidden>)

  • Prev by Date: Creating a console view
  • Next by Date: Re: Creating a console view
  • Previous by thread: Creating a console view
  • Next by thread: Re: Creating a console view
  • Index(es):
    • Date
    • Thread