Re: NSMutableAttributedString attributesAtIndex:effectiveRange: dictionary autoreleased?
Re: NSMutableAttributedString attributesAtIndex:effectiveRange: dictionary autoreleased?
- Subject: Re: NSMutableAttributedString attributesAtIndex:effectiveRange: dictionary autoreleased?
- From: Michael Ash <email@hidden>
- Date: Sat, 14 Aug 2010 11:29:40 -0400
On Sat, Aug 14, 2010 at 7:56 AM, Eyal Redler <email@hidden> wrote:
> Hi,
>
> I can't find any mention of if in the documentation but I need to know: how safe is it to use the dictionary returned from "attributesAtIndex:effectiveRange" after I've made changes to the attributed string? More specifically, I'm worried that maybe what I'm getting (at least sometimes) is not a copy of the dictionary at that point but the actual mutable dictionary off the string data structure and that it may be changed when I'm making changes to the attributed string.
>
> For example:
>
> NSDictionary* myAttributes;
>
> [myMutableAttributedString addAttribute:@"my attribute" value:[NSNumber numberWithInt:10] range:NSMakeRange(0,10)];
>
> myAttributes=[myMutableAttributedString attributesAtIndex:4 effectiveRange:NULL];
>
> [myMutableAttributedString addAttribute:@"my attribute" value:[NSNumber numberWithInt:20] range:NSMakeRange(0,10)];
>
> anAttribute=[myAttributes attributesAtIndex:4 effectiveRange:NULL];
>
> Is anAttribute guaranteed to be equal to 10?
If the documentation doesn't say it's guaranteed, then it's not.
If you're uncertain, why not just make your own copy? If
NSAttributedString is already making a copy, then you're copying an
immutable object, which is almost free. If it's not, then you're
saving your bacon, so the extra cost is worth it.
Mike
_______________________________________________
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