Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You need to rework your method to work asynchronously, like <code>-openWithCompletionHandler:</code>. It needs to take a block which is invoked when the answer is known and which receives the answer, true or false, as a parameter.</p> <p>Then, the caller should pass in a block that does whatever is supposed to happen after the answer is known.</p> <p>Or, alternatively, you should delay the whole chunk of logic which cares about the photo being in the database. It should be done after the open has completed.</p> <p>You'd have to show more code for a more specific suggestion.</p> <hr> <p>So, you could rework the <code>isPhoto...</code> method to something like:</p> <pre><code>+ (BOOL)checkIfPhoto:(NSString *)photoToCheck isInManagedDocument:(UIManagedDocument *)document handler:(void (^)(BOOL isHere))handler { if (document.documentState == UIDocumentStateClosed) { [document openWithCompletionHandler:^(BOOL success) { handler([Photo isPhoto:photoToCheck here:document.managedObjectContext]); }]; } else handler(NO); } </code></pre> <p>Then you can rework this:</p> <pre><code>- (IBAction)queryFromDatabase:(UIButton *)sender { NSURL *url = [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject]; url = [url URLByAppendingPathComponent:@"test"]; UIManagedDocument *defaultDocument = [[UIManagedDocument alloc] initWithFileURL:url]; [checkPhoto checkIfPhoto:@"test" isInManagedDocument:defaultDocument handler:^(BOOL isHere){ if (isHere) { [sender setTitle:@"Okay" forState:UIControlStateNormal]; } else { [sender setTitle:@"NO" forState:UIControlStateNormal]; } }]; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload