Last active
August 29, 2015 14:16
-
-
Save joshdholtz/842a4e9d6a5a496ddb7b to your computer and use it in GitHub Desktop.
Get RLMResults after writing multiple objects
This file contains hidden or 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
/* | |
* The reason I am looking for this as an RLMResults so I can query Realm before my request to get new data comes back. | |
* I want both the local querying and the creating/updating to return in the same format (RLMResults) | |
* | |
* I am new to Realm so please tell me if I should be going about this a different way. | |
*/ | |
+ (RLMResults*)saveResponse:(NSArray*)response { | |
// Gets real and creates set of ids that were added/updated | |
RLMRealm *realm = [RLMRealm defaultRealm]; | |
NSMutableSet *ids = [NSMutableSet set]; | |
// Save building data | |
[realm beginWriteTransaction]; | |
[response rs_each:^(NSDictionary* item) { | |
BuildingModel *building = [BuildingModel createOrUpdateInRealm:realm withObject:item]; | |
[ids addObject:[NSNumber numberWithInteger:building.ID]]; | |
}]; | |
[realm commitWriteTransaction]; | |
return [BuildingModel objectsInRealm:realm withPredicate:[NSPredicate predicateWithFormat:@"id IN %@", ids]]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment