I have a view with a UIPageViewController and on the method to set view controllers I have use a thread safe instance of self like this:
__block typeof(self) threadedSelf = self;
[self.pageController setViewControllers:@[p]
direction:UIPageViewControllerNavigationDirectionReverse
animated:YES
completion:^(BOOL finished){
if (finished) {
[threadedSelf performSelectorOnMainThread:@selector(setNavTitleText) withObject:nil waitUntilDone:NO];
}
}];
The completion block looks similar to other completion blocks, like the UIView animation method, but this is the first completion block where I've had to create a block version of self. Why is this method different than other completion callbacks? Is it because this is an instance method where the UIView animation is a class (static) method?
threadedSelfin the first place? You are making an initial assumption here; why? Is it becausesetViewControllersis being called on a background thread? If so, why are you doing that? - mattselfwere to vanish out from under you, the weak-strong dance allows you to detect safely the resulting nil weak ref and go no further. I have never seen__blockused in that way and it is not what Apple officially recommends in their WWDC videos; they do the weak-strong dance (and they even call it that; I believe they got that name from me, but I could be wrong, maybe it existed before I started using it :) m. - matt