On Jul 11, 2012, at 7:34 AM, [email protected] wrote: > I still disagree, in the sense that, as a client, I would never expect the > contents of an NSArray to change (only the array assigned to the property). > In practice, that may not matter. In any case, I can live with it.
As Ken Thomases said, this expectation is unfounded. Think of it this way: you can have the same expectations of a NSArray as you have with a standard C array reference. This is, of course, an extremely simplified statement but to go along with it here are some equally simplified examples: void * someArrayReference = someObject.arrayReference(); NSArray * someNSArray = [someObject array]; Ignoring threading and related issues, you can expect that the reference (pointer) to the array will not change and that the contents of the array will not change⦠as long as you don't do anything that may allow something else to change. A very simple example of such actions would be: someObject.addUser( someUser ); // where someArrayReference is a reference to the user array And of course you wouldn't expect that either the reference or the array contents would not change after exiting the method where you retrieved the reference. In other words, each call to someObject.arrayReference() may return a different array reference or for the data in the array to have changed since the last call. As with anything, you can over think this. Even my simplified explanation here is really over done; simply put: An NSArray reference and it's contents can be expected to never change within the scope of a single use, but not between uses. As far as the implementation goes, I use William Squires' method of implementing this pattern (public read-only NSArray property that refers to the private read-write NSMutableArray property); it's very simple and provides exactly what you are looking for (if not exactly what you are expecting). -lane
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________ Cocoa-dev mailing list ([email protected]) 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: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [email protected]
