On Jun 3, 2008, at 8:56 AM, Karl Moskowski wrote:

Would it be sufficient to cast, like this?
        :
        return (NSData *)myData;

Does this generalize to other non-collection classes, e.g., NSString?


In the general case yes. I would say that it's not up to you to ensure that this object is not being accidently mutated at some later point - you already declared the returned object to be of an immutable type.

If someone later needs to ensure that they hold an immutable and private copy, they can always copy it at that point. If the object being copied is already immutable, this is typically cheap. See the "Copying Mutable Versus Immutable Objects" optimization here:

<http://developer.apple.com/documentation/Cocoa/Conceptual/MemoryMgmt/Tasks/ImplementCopy.html#//apple_ref/doc/uid/20000049-999791 >

j o a r


_______________________________________________

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 [EMAIL PROTECTED]

Reply via email to