• 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: Swift: what is the difference between properties and functions?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Swift: what is the difference between properties and functions?


  • Subject: Re: Swift: what is the difference between properties and functions?
  • From: Quincey Morris <email@hidden>
  • Date: Fri, 01 Aug 2014 10:39:56 -0700

On Aug 1, 2014, at 10:00 , William Squires <email@hidden> wrote:

I'm not sure there is any.

I can think of two practical differences:

1. (the obvious one, but no one said it yet) The trailing “()” must be written to invoke the method.

2. The method is a closure, but the property isn’t. (For example, for use with Array’s ‘map’ method.)

There’s a semantic difference, too — properties are typically “has a …”, while methods are everything else. (In Gerriet’s example, if weather “has” a forecast, it should be a property; but if you need to “make” a forecast, it should be a method. Probably.)

In general, properties also have backing storage. I don’t recall noticing if Swift is explicit about whether read-only computed properties still have backing storage (probably not, for classes, but for structs, IDK, they might).

The last difference I can think of is that for Objective-C classes at least, there’s additional run-time introspection information for properties. I’d guess that the same is true for pure-Swift classes, but AFAIK we can’t introspect that information (yet) so it’s a moot point.

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >Swift: what is the difference between properties and functions? (From: "Gerriet M. Denkmann" <email@hidden>)
 >Re: Swift: what is the difference between properties and functions? (From: William Squires <email@hidden>)

  • Prev by Date: Re: Swift: what is the difference between properties and functions?
  • Next by Date: Re: XCode 5 - Logging
  • Previous by thread: Re: Swift: what is the difference between properties and functions?
  • Next by thread: Re: Swift: what is the difference between properties and functions?
  • Index(es):
    • Date
    • Thread