Re: Satisfying a protocol - getters vs. functions
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