Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save hhanesand/d3bf5c87b0a925f4e4cbab48d0d5e4e4 to your computer and use it in GitHub Desktop.
Save hhanesand/d3bf5c87b0a925f4e4cbab48d0d5e4e4 to your computer and use it in GitHub Desktop.
+ (void)writeTransactionWithDefaultRealm:(void(^)(RLMRealm *realm))block completion:(void (^_Nullable)(void))completion {
@autoreleasepool {
RLMRealm *realm = [self openRealm];
if (realm.inWriteTransaction) {
safe_block(block, realm);
return safe_block(completion);
}
// Fire any notifications waiting before we start a write tranaction
[realm refresh];
NSError *error = nil;
[realm transactionWithBlock:^{
safe_block(block, realm);
} error:&error];
if (error) {
NSLog(@"Warning : realm write error : %@", error);
}
safe_block(completion);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment