- 循环引用的weak用法

        // ** {} 中所有 self 都是弱引用,注意需要解包
        // 1、类似于 OC 中的 __weak typeof(self) weakSelf = self;

         weak var weakSelf = self
        test2 { (res) in
            print(res)
            weakSelf?.view.backgroundColor = UIColor.red
        }

        // 2、[weak self]

        test2 { [weak self] (res) in
            print(res)
            self?.view.backgroundColor = UIColor.orange
        }
    func test2(com: (_ :String)->()) {
        let str = "---- test2 ----"
        com(str)
    }

 

posted on 2017-08-21 14:44  xiao孛  阅读(220)  评论(0编辑  收藏  举报