Push Notifications · Action Category | raywenderlich.com

This is a companion discussion topic for the original entry at https://www.raywenderlich.com/1258151-push-notifications/lessons/7

Would like to know a basic thing, you capture a weak reference before using it… why so?
I mean, it has something to do with garbage collection and optimising app for resources, but once viewdidload exits, the reference is automatically destroyed, right?

from Capturing Self with Swift 4.2

…the case where you need to call a method on self inside the block. The block will retain self and you’ve just created a bi-directional dependency graph, otherwise known as a retain cycle .

This is bad because it means self can’t ever be released as long as the block lives. Often times the blocks are stored as properties on the instance, or as observers for KVO or notifications, and their lifetime is bound to self .

1 Like

Thanks for the reference material!