This should not create a reference loop, but even if everything was fine. The reference cycle will exist only until the animation is completed, after which it will be broken. Creating short-lived reference loops can be useful because it ensures that the target continues to exist for the life of the call. Loops are not inherently a problem. Inevitable cycles are a problem.
There are two reasons why this does not create a loop. Firstly, there is no "cycle". The system will refer to something (moreover, for a second), of course. But where is the link to "a thing that refers to something?" To say this a little more clearly, even if the animation system refers to self , how does self refer to the animation system? There is no cycle.
Another reason there is no loop is because you still don't go through self in the animation system. Walkthrough self.view.layoutIfNeeded . In Swift, this is equivalent to:
UIView.layoutIfNeeded(self.view)
You do not miss self here. You are viewing a presentation. Now, the animation system will almost certainly refer to this view until the animation finishes, but itβs fine. This is not a cycle yet.
source share