| |||
| [Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] |
A question I've had is when a container is said to be immutable, is it still fair game to change the contents of the objects that are contained?
For example: An NSArray containing NSMutableString objects, or an NSData object. Can you / Should you change the contents of the NSMutableStrings in the NSArray or the Memory block pointed to by the NSData?
Should items contained in immultable container classes be considered immutable?
Not necessarily. Your design should specify if this is the case, otherwise it's most likely assumed that the immutability attribute applies only to the container, not it's contents. This is consistent with the rest of Foundation's container behaviour, and that of other common containers such as found in the STL (where everything, most notably copies, are shallow in so far as containers holding pointers are concerned).
[snip]P.S. Sorry for taking this further off-topic. As far as the OP goes, the main effeciency point I've seen when dealing with mutable Vs. immutable is that a copy of an immutable object can just be a reference to the same object, but a mutable copy needs to be a full copy. Things is, why do you need a copy? If it's to change it, then it needs to be mutable, and you need a full copy. If it's just to call it by a different name, then regardless of wether it's a mutable object or not you just need to pass a reference around.
From the converse point of view, if you want a mutable object because you know you'll change it, you mightn't want to limit your callers to providing a mutable version of the object... ultimately it's easier to call mutableCopy once in your target method than in some, most or even all your callers. As with the immutable case just mentioned, if the given object is already of the correct mutability you'll just end up retaining it.I think we're thinking the same way, but saying it differently.
| References: | |
| >Copy and release (From: Nicko van Someren <email@hidden>) | |
| >Re: Copy and release (From: Evan Schoenberg <email@hidden>) | |
| >Re: Copy and release (From: Nicko van Someren <email@hidden>) | |
| >Re: Copy and release (From: Paul Sargent <email@hidden>) | |
| >Re: Copy and release (From: Wade Tregaskis <email@hidden>) |
| Home | Archives | FAQ | Terms/Conditions | Contact | RSS | Lists | About |
Visit the Apple Store online or at retail locations.
1-800-MY-APPLE
Contact Apple | Terms of Use | Privacy Policy
Copyright © 2007 Apple Inc. All rights reserved.