I am really stumped with this one. I have been reading all the info I can get my hands on about how to properly handle variables inside blocks.
Note: I am not using arc.
So, say I have an animation that looks like this:
[UIView animateWithDuration:.5 animations:^{
textCard.alpha = 1.f;
self.dotView.alpha = 1.f;
self.subtitles.alpha = 0;
}completion:^(BOOL finished){
[self.playerLayer removeFromSuperlayer];
self.playerLayer = [AVPlayerLayer playerLayerWithPlayer:self.vidPlayer];
self.playerLayer.frame = self.vidView.bounds;
[self.vidView.layer insertSublayer:self.playerLayer atIndex:0];
[self.subtitles removeFromSuperview];
self.subtitles = [sub autorelease];
[UIView animateWithDuration:.3 delay:1 options:UIViewAnimationOptionAllowUserInteraction animations:^{
textCard.alpha = 0.f;
sub.alpha = 1.f;
}completion:^(BOOL finished){
self.queuedVid = NO;
if (self.shouldPlay == YES) {
[self.vidPlayer play];
[self setCurrentVideoSettings];
}
else{
self.shouldPlay = YES;
}
[textCard removeFromSuperview];
textCard = nil;
}];
}];
Now this code probably looks a little arbitrary but here is a very real world example of something I have to do.
Here are my two problems:
If I leave this as is and the class (tries) to get deallocated during the invocation of this block, it will not release.
If I change self to
__block typeof (self) weakRef = self;
then if the class gets deallocated before the second block can run, it crashes because it is trying to reference my deallocated self.
I know I just must not understand how this works, but if anyone can shed some light, I would appreciate it.