Thursday, January 16, 2014

Associated Objects on Value Types

Greg Parker notes that one should not use objc_setAssociatedObject() to attach associated objects to immutable value-like types such as NSNumber, NSDate, and NSString. The reason is that, due to de-duplication and tagged pointers, the objects may be shared and/or immortal.

2 Comments RSS · Twitter

There are also classes which you might not think of as value types which are deduplicated, such as UIFont.

@Jens Yes, fonts too, since the documentation says they are immutable and “These methods check for an existing font object with the specified characteristics and return it if it exists.”

Leave a Comment