Re: Very annoying bug with NSMutableAttributedString
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.