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.
|