[swift-evolution] a few initializer proposals

Mike Kluev mike.kluev at gmail.com
Thu Jun 22 18:55:38 CDT 2017


On 23 June 2017 at 02:39, Mike Kluev <mike.kluev at gmail.com> wrote:

>
> if a single private var has no implicit / explicit default value then
> default member wise initialiser is not created (#change) and attempt to
> opt-in to have one gives an error. let's call it proposal #5. this
> particular one is not a backward compatible change, the old code will have
> to be modified.
>

alternatively:

in case of private members with no implicit / explicit default values, we
may have a private memberwise initialiser with all private member
parameters as well. you can create your own public initializer and call
through the private memberwise initializer if needed

struct S {
  var a: Int
  var b: Int = 0

  private var c: Int
  private var d: Int?

// autogenerated (#change)
//
//  private init(a: Int, b: Int = 0, c: Int, d: Int? = nil) {   // private
//    self.a = a
//    self.b = b
//    self.c = c
//    self.d = d
//  }

  init(... whatever ...) {
    self.init(a: ...., b: ....., c: ...., d: ....)
  }
}

Mike
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170623/4013be3b/attachment.html>


More information about the swift-evolution mailing list