• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: const correctness
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


References: 
 >const correctness (From: Luther Baker <email@hidden>)
 >Re: const correctness (From: Jens Alfke <email@hidden>)
 >Re: const correctness (From: Luther Baker <email@hidden>)

  • Prev by Date: Re: SMJobBless - how to start helper tool?
  • Next by Date: Re: const correctness
  • Previous by thread: Re: const correctness
  • Next by thread: SMJobBless - how to start helper tool?
  • Index(es):
    • Date
    • Thread