On Sat, Aug 14, 2010 at 7:56 AM, Eyal Redler <eyred...@netvision.net.il> 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 (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com