Your First Swift 4 & iOS 11 App - Part 32: | Ray Wenderlich

Learn how to use an important construct in Swift called closures, which you often use to provide a block of code that is executed some time in the future.


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/3990-your-first-swift-4-ios-11-app/lessons/32

isn’t a “weak self” required here?

The reason you sometimes need to use weak self is to avoid retain cycles, where an object (like a view controller) holds an object that has a reference back to the object (like using self within a closure).

In this case, we don’t store the alert object in a property on the view controller so don’t need it. For more details, see this: ios - Should self be captured as strong in a UIAlertAction's handler? - Stack Overflow

actually only in the Instruments course with Luke did i understand about the retain cycle concept, clearly.
thanks!

Cool! Glad to hear that Luke’s explanation helped.

This topic was automatically closed after 166 days. New replies are no longer allowed.