None of them will create save cycles, since the block is not bound to self
. In addition, maintaining cycles with a guaranteed service life is not the worst thing in the world.
Let's look at some examples. (Sorry, my fast is not particularly strong, so I will return to obj-c.)
- (void)doSomething:(void(^)())block { self.block = block; }
This creates a save loop because self
refers (not weakly) within the block to which self
contains a reference.
[UIView transitionWithView:self duration:5, options:UIViewAnimationOptionTransitionCrossDissolve animations:^{ [self setNeedsDisplay]; } completion:nil];
This does not create a save loop because the animations
block is sent to the system - your UIView
subclass UIView
not contain a reference to the block.
Side note . You do not need to have return
at the end of your closure, but I think swift is ridiculous and trying to be "useful." Also, I'm not sure if you need to call self.setNeedsDisplay()
during the animation, as it should do it by itself ...
source share