• 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: Appending string to NSTextView crashing app
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Appending string to NSTextView crashing app


  • Subject: Re: Appending string to NSTextView crashing app
  • From: Ryan Stevens <email@hidden>
  • Date: Tue, 24 Apr 2007 20:16:35 -0700

- (void)appendString:(NSString *)string toView:(NSTextView *)view
{
  if (string == nil) { return; }

  string = [string stringByAppendingString:@"\n"];

  NSAttributedString *stringToAppend =
    [[NSAttributedString alloc] initWithString:string];

  [[view textStorage] appendAttributedString:stringToAppend];

[stringToAppend release];
}

You don't need to make the text view editable to add to its textStorage. You do need to release what you alloc/init - read up on memory management. I got rid of the subString which should've been released as well - appending is more logical and is likely faster than initWithFormat: anyway.

Hope that helps.

On Apr 24, 2007, at 7:29 PM, Evan Moseman wrote:

I'm hoping somebody can help me with this, I'm trying to append text to an NSTextView using this function:

- (void)appendString:(NSString *)string toView:(NSTextView *)view
{
if (string == nil) { return; }
[view setEditable:YES];
NSString *subString = [[NSString alloc] initWithFormat:@"%@\n", string];
NSAttributedString *stringToAppend =
[[NSAttributedString alloc] initWithString:subString];
[[view textStorage] appendAttributedString:stringToAppend];
[view setEditable:NO];
}



But, after about 10 strings, the whole app crashes with a seg fault. I can print the strings using NSLog and it never crashes. Is there something wrong with the above code? Should I try using bindings?


Any help is greatly appreciated!

Thanks!

--
Evan
_______________________________________________

Cocoa-dev mailing list (email@hidden)

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: Appending string to NSTextView crashing app
      • From: Evan Moseman <email@hidden>
References: 
 >Appending string to NSTextView crashing app (From: Evan Moseman <email@hidden>)

  • Prev by Date: Using OpenSSL with the Security framework
  • Next by Date: Re: Appending string to NSTextView crashing app
  • Previous by thread: Appending string to NSTextView crashing app
  • Next by thread: Re: Appending string to NSTextView crashing app
  • Index(es):
    • Date
    • Thread