阅读背景:

避免在闭包中捕获值副本的最佳方法

来源:互联网 
struct Foo {

    var i = 0 { didSet { println("Current i: \(i)") } }

    func delayedPrint() {
        dispatch_async(dispatch_get_main_queue(), { _ in
            println("Closure i: \(self.i)")
        })
    }

    mutating func foo() {
        delayedPrint()
        i++
    }
}
struct Foo {

    var i = 0 { didSet { println(



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: