The code inside async {}
will b executed asynchronously. The completion function ({ [weak self] ... }
) contains a (default strong) reference to the object calling the async
function.
Since it is asynchronous you don't have a way to know a) when the callback will be executed b) if it will be executed. Meaning that the strong reference to self
could cause a memory leak.
That is why one uses [weak self]
to pass a weak reference. Since the call is async, it can be that, when the callback is finally executed, the ARC has already collected the reference to self
and thus self
would be nil
.
It is then good to check if self
still exists before executing the code in the callback.