[swift-evolution] [Proposal Draft] Flexible memberwise initialization

Guillaume Lessard glessard at tffenterprises.com
Tue Dec 22 13:36:26 CST 2015


(adding on)

> On 22 déc. 2015, at 12:02, Matthew Johnson <matthew at anandabits.com> wrote:
> 
> Why would you have an immutable instance member that is always going to have a constant value of 1?

That’s obviously a toy example. You can also use function calls, and that’s useful:

public struct A {
  public let property = random()
}

Would it make sense to allow a user in a different module write an extension that subverts the `let` by assigning via a new initializer?

extension A {
  init(_ value: Int) {
    self.property = value // ouch!
  }
}

Cheers,
Guillaume Lessard



More information about the swift-evolution mailing list