class A {
    func foo() -> ()->String {
        func local() -> String { [weak self] in 
            return "foo \(self.i)"
        }
        return local
    }
...

compares well with this...

class A {
    func foo() -> ()->String {
        let local : () -> String = { [weak self] in
            return "foo \(self?.i)"
        }
        return local
    }
    func foo2() -> ()->String {
        let local : () -> String = {
            return "foo2 \(self.i)"
        }
        return local
    }
    let i : Int
    init(_ i: Int) { self.i = i }
}
var a = A(2)
let b = a.foo()
a = A(4)
print(b()) // prints "foo nil"

let b2 = a.foo2()
a = A(6)
print(b2()) // prints "foo2 4"

--
C. Keith Ray

* https://leanpub.com/wepntk <- buy my book?
* http://www.thirdfoundationsw.com/keith_ray_resume_2014_long.pdf
* http://agilesolutionspace.blogspot.com/

> On Oct 25, 2017, at 1:21 PM, David Hart via swift-evolution 
> <swift-evolution@swift.org> wrote:
> 
> class A { func foo() { func local() -> Int { [weak self] in } } }
_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

Reply via email to