Question

I am creating or opening a UIManagedDocument in my AppDelegate, using completion handler blocks to notify me when the document is ready for use.

   // CHECK TO SEE IF MANAGED DOCUMENT ALREADY EXISTS ON DISK
    if([fileManager fileExistsAtPath:[documentLocation path]]) {

        // EXISTS BUT CLOSED, NEEDS OPENING
        [[self managedDocument] openWithCompletionHandler:^(BOOL success) {
            NSLog(@"DOCUMENT: Opened ...");
            // TODO: Things to do when open.
        }];
    } else {
        //DOES NOT EXIST, NEEDS CREATING AND OPENING
        [[self managedDocument] saveToURL:documentLocation forSaveOperation:UIDocumentSaveForCreating completionHandler:^(BOOL success) {
            NSLog(@"DOCUMENT: Created & Opened ...");
            // TODO: Things to do when open.
        }];
    }

My question is I want to setup a NSFetchedResultsController on my ViewController but currently the controllers view loads before the document (from the AppDelegate) is either created or opened. I am just curious about how I inform the controller that the document is open and ready to use. My guess is I would use a NSNotification, but I just wanted to check I am not going about this the wrong way.

Was it helpful?

Solution

If you have a instance of your ViewController in appDelegate then write a public method in your ViewController and call this method in the block completion handler.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top