openWithCompletionHandler
works asynchronously, which means that it only initiates opening the document in the background. The completion handler block is called later, when the document actually has been opened.
So you cannot call [self readAllQuestions]
directly after [self openDocumentIfItExistsOrCreateNew]
. You could for example move that into the completion handler block:
[document openWithCompletionHandler:^(BOOL success) {
if (success) {
[self readAllQuestions];
... update UI (reload table view or whatever you have) ...
} else {
// report error
}
}];