• 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: Very annoying bug with NSMutableAttributedString
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Very annoying bug with NSMutableAttributedString


  • Subject: Re: Very annoying bug with NSMutableAttributedString
  • From: "Louis C. Sacha" <email@hidden>
  • Date: Tue, 27 Apr 2004 06:59:20 -0700

Hello...

The problem seems to be that initWithString:attributes: can not handle an empty dictionary or nil passed as the attributes dictionary. If the dictionary contains any key/value pair, then everything seems to work correctly.

A simple work around would be to check before creating the attributed string, and only use the initWithString:attributes: initializer if the attributes dictionary is valid.

For example, given:

NSDictionary *defaultAttributes; // which may be nil, empty, or a valid dictionary of attributes
NSString *yourString = @"test string";

You could do:

NSMutableAttributedString *MAS2;
if ([defaultAttributes count]) {MAS2 = [[NSMutableAttributedString alloc] initWithString:yourString attributes:defaultAttributes];}
else {MAS2 = [[NSMutableAttributedString alloc] initWithString:yourString];}


As Nick mentioned, if you haven't already, you should file your bug at bugreporter.apple.com to make sure that Apple is aware of the problem.

Hope that helps,

Louis


NSMutableAttributedString * MAS2 = [[[NSMutableAttributedString
alloc] initWithString: @"X" attributes: [NSDictionary dictionary]]
autorelease];
...
NSLog(@"MAS2 is: %@", [MAS2 description]);
...
2004-04-27 11:50:53.599 NSMAS[17267] *** Uncaught exception:
<NSRangeException> *** -[NSCFString substringWithRange:]: Range or
index out of bounds
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.


References: 
 >Very annoying bug with NSMutableAttributedString (From: Jérôme Laurens <email@hidden>)

  • Prev by Date: Re: Very annoying bug with NSMutableAttributedString
  • Next by Date: Re: xCode 1.2
  • Previous by thread: Re: Very annoying bug with NSMutableAttributedString
  • Next by thread: ContextualMenus and app launch question
  • Index(es):
    • Date
    • Thread