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

Myles Schultz myleslschultz at icloud.com
Sun Feb 14 13:03:36 CST 2016


Isn't this already something one can do with closures?

Myles

Sent from my iPhone

> On Feb 14, 2016, at 12:04 PM, Amir Michail via swift-evolution <swift-evolution at swift.org> wrote:
> 
> 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
>  }
> }
> 
> _______________________________________________
> 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