Start a new topic

Core Data Object Deletion Not Updating!

I'm using Core Data with Kinvey, when I create or edit a change via the console it updates in NSFetchedResultsController however when I delete an object it still says there.

Any ideas?

Also I'm having trouble with saving cached objects, any clue? It's so hard familiarising yourself with other SDKs after moving from Stackmob...
The iOS delete methods don't remove the object from memory or the managed object context. You'll have to do that yourself in the completion block. For more detail, see this guide http://devcenter.kinvey.com/ios/guides/coredata
Okay, I've come up with the following code:



```[self.store queryWithQuery:[KCSQuery query] withCompletionBlock:^(NSArray *objectsOrNil, NSError *errorOrNil) {

NSArray *objs = [Task MR_findAll];

NSMutableArray *serverIds = [NSMutableArray array];

for (id object in objectsOrNil) {

if ([[object valueForKey:@"kinvey_id"] length] > 0) {

[serverIds addObject:[object valueForKey:@"kinvey_id"]];

}

}

NSMutableArray *localIds = [NSMutableArray array];

for (id object in objs) {

if ([[object valueForKey:@"kinvey_id"] length] > 0) {

[localIds addObject:[object valueForKey:@"kinvey_id"]];

}

}

[localIds removeObjectsInArray:serverIds];

if (localIds.count > 0) {

for (NSString *kinvey_id in localIds) {

NSArray *result = [objs filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"kinvey_id == %@",kinvey_id]];

if (result.count > 0) {

[self.editingContext deleteObject:[result objectAtIndex:0]];

}

}

[self.editingContext MR_saveToPersistentStoreAndWait];

}

} withProgressBlock:^(NSArray *objects, double percentComplete) {

NSLog(@"Percent Complete: %f",percentComplete);

}];```



Is this okay? The core data guide isn't very specific, if you could elaborate that'd be great. Also when the device is offline the offline-created objects aren't uploaded. The caching guide isn't too helpful.
Login or Signup to post a comment