Created
November 6, 2017 18:30
-
-
Save hhanesand/d3bf5c87b0a925f4e4cbab48d0d5e4e4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
+ (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