[swift-evolution] Proposal: instance variable declarations inside methods

Amir Michail a.michail at me.com
Sun Feb 14 11:04:30 CST 2016


For example:

class A {
  var c = 0
  func getAndIncCount() -> Int {
    let v = c
    c++
    return v
  }
}

Could be refactored as:

class A {
  func getAndIncCount() -> Int {
    instance var c = 0 // this instance variable for class A is only accessible in this method
    let v = c
    c++
    return v
  }
}



More information about the swift-evolution mailing list