Shall we always use [unowned self] inside closure in Swift

前端 未结 9 2133
耶瑟儿~
耶瑟儿~ 2020-11-22 05:22

In WWDC 2014 session 403 Intermediate Swift and transcript, there was the following slide

\"enter

9条回答
  •  眼角桃花
    2020-11-22 06:01

    If self could be nil in the closure use [weak self].

    If self will never be nil in the closure use [unowned self].

    The Apple Swift documentation has a great section with images explaining the difference between using strong, weak, and unowned in closures:

    https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/AutomaticReferenceCounting.html

提交回复
热议问题