For the issue of when there is a delete on the server side, it means we have less data on the server side
than the local side.
we need to make sure our local db sync up to that. One way to do that is to pull the data by using MSTable’s
readWithCompletion to get the latest from the server.
Than compare it to the core data.
In your QS******Service.m,
declare some properties to save data:
1 2 |
@property (nonatomic, strong) NSMutableArray *loadedItems; @property (nonatomic) BOOL moreResults; |
Then, we implement a method where we store the results from the server. We use MSTable’s
readWithCompletion method like so:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
-(void)loadResultsFromServerWithCompletion:(void (^)(NSArray * result))complete { __block NSMutableArray * myResults = [NSMutableArray array]; MSTable *itemTable = [self.client tableWithName:@"TodoItem"]; [itemTable readWithCompletion:^(MSQueryResult * _Nullable result, NSError * _Nullable error) { NSLog(@"finished receiving from remote server"); if(error) { // error is nil if no error occured NSLog(@"ERROR %@", error); } else { for(NSDictionary *item in result.items) { // items is NSArray of records that match query NSLog(@"Server side - Todo Item: %@", [item objectForKey:@"text"]); [myResults addObject: item]; } complete(myResults); } }]; } |
Then when you get the latest results
1 2 3 4 5 6 |
[self loadResultsFromServerWithCompletion:^(NSArray *result) { NSLog(@"%@", result); //then maybe we can compare server and local. //if server is less than local, make sure we remove local. }]; |