I am using a UIDocument subclass which has the potential have its saveToURL
method called from more than one thread. I have therefore encapsulated it in a wrapper function which I want to make thread safe:
- (void)saveWithCompletionBlock:(void(^)(TransactionDocumentReturnCode status))completion {
@synchronized (self) {
[self saveToURL:[self fileURL] forSaveOperation:UIDocumentSaveForOverwriting completionHandler:^(BOOL success){
// Generate returncode depending on outcome of save operation
completion(returncode);
}];
}
}
I am assuming that the call to [self saveToURL:...]
will return immediately since the save operation itself occurs on a background thread, causing the lock to be released potentially before the save operation is completed. So, is there any way to keep other threads calling saveWithCompletionBlock:
blocked until saveToURL
's completion block has been called?