Re: const correctness
Re: const correctness
- Subject: Re: const correctness
- From: Jens Alfke <email@hidden>
- Date: Sun, 18 Mar 2012 11:27:36 -0700
On Mar 17, 2012, at 10:58 PM, Luther Baker wrote:
> I was ruminating about it more of a (self) documenting angle as opposed to runtime enforcement …
Cocoa’s idioms are different. In Cocoa you use mutable vs. immutable container types to indicate this. So if a method parameter is NSMutableString*, that means the method is allowed to modify the string. If the parameter is NSString*, it isn’t allowed to modify it (even if you actually passed in an NSMutableString*.) Likewise, no method declared in NSString’s @interface is allowed to modify the contents of the string, even if you call it on an NSMutableString.
In other words, look for the ‘Mutable’ in the class name the way you would look at ‘const’ in a C++ API.
—Jens
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden