You can execute the block with completionBlock(doc).
[doc openWithCompletionHandler:^(BOOL success)
{
// Can I call the completionBlock from above in here?
// How do I pass back the opened UIDocument
completionBlock(doc);
}];
Let's assume that you have the following method implemented in the class that will be calling your openVacation method:
-(void)vacationOpened:(UIManagedDocument *)vacation
{
NSLog(@"My Vacation: %@", vacation.description);
}
A sample line of code that would call your openVacation method would be:
[MyVacationsHelper openVacation:@"MyVacation1" usingBlock:^(UIManagedDocument *vacation){
[self vacationOpened:vacation];
}];
The (UIManagedDocument *vacation) after the caret means that when you execute the block using the parentheses notation -- as in completionBlock(doc) --, you need to list a (UIManagedDocument *) as a parameter. The value of that parameter will be referred to as vacation inside the specified block. What I did in my block code sample above was call a method in my current class (self) and pass the parameter along to that method so that I could use it as needed (I just did an NSLog here to make sure that it worked).
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…