• 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: Satisfying a protocol - getters vs. functions
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Satisfying a protocol - getters vs. functions


  • Subject: Re: Satisfying a protocol - getters vs. functions
  • From: Quincey Morris <email@hidden>
  • Date: Sat, 25 Jun 2016 13:06:34 -0700
  • Feedback-id: 167118m:167118agrif8a:167118sypJLVT7Dd:SMTPCORP

On Jun 25, 2016, at 12:49 , William Squires <email@hidden> wrote:
>
> I was looking at the problem from the caller's end (i.e. client code), not the callee's end, so the semantic requirements (such as getters not being able to modify instance variables) aren't a consideration here.

It does, subtly, affect the caller’s end, too. The fact that it’s a property rather than a function allows the compiler to apply different optimizations (because it knows that the value is immutable, for example), not to mention giving a reader of the code a hint that there are no side effects from examining the property value, at least not on the value itself.

I should also have mentioned earlier that if the property and function are @objc, then as a matter of implementation they’re identical, but the compiler still won’t let you confuse them in Swift code. I’d expect an error message if you tried to put both in the same class, because you’d essentially have duplicate names.

_______________________________________________

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: 
 >Satisfying a protocol - getters vs. functions (From: William Squires <email@hidden>)
 >Re: Satisfying a protocol - getters vs. functions (From: William Squires <email@hidden>)

  • Prev by Date: Re: Satisfying a protocol - getters vs. functions
  • Next by Date: Re: Are NSFileWrappers safe for concurrent access?
  • Previous by thread: Re: Satisfying a protocol - getters vs. functions
  • Next by thread: NSTask argument list
  • Index(es):
    • Date
    • Thread