[swift-evolution] [proposal] Allow "let" for computed properties which only reference immutable data

Alexander Momchilov alexandermomchilov at gmail.com
Wed May 11 08:25:54 CDT 2016


I came an interesting SO question
<http://stackoverflow.com/a/37161488/3141234> which pointed out a strange
quirk: a computed property must always use the "var" keyword, even if it's
read-only, and only referencing other immutable data.

class Test {
  let hello = "hello"
  let world = "world"
  var phrase: String { //why must this be 'var'?
     return self.hello + self.world
  }}

It would be more appropriate for such a read-only, immutable property, to
use the "let" syntax, so that its immutability is correctly expressed.

Thoughts?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160511/bcce5725/attachment.html>


More information about the swift-evolution mailing list