[swift-evolution] [proposal] Allow "let" for computed properties which only reference immutable data
Sean Heber
sean at fifthace.com
Wed May 11 10:26:46 CDT 2016
I kind of agree with the logic of that, but imagine the following:
class Test {
let hello = “hello”
var subject = “world”
var phrase: String { return hello + “, “ + subject }
}
In this scenario, “subject” can be changed.. and that changes the result of “phrase”. Things like this are why computed properties are “var”.
l8r
Sean
> On May 11, 2016, at 8:25 AM, Alexander Momchilov via swift-evolution <swift-evolution at swift.org> wrote:
>
> I came an interesting SO question 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?
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution
More information about the swift-evolution
mailing list