0

I'm new in StackMob, so please excuse me for this basic question. The tutorials there are lacking.

When I create a new object and save the NSManagedObjectContext right away, the object is saved successfully.

But normally when I use core data, I save the context only in applicationDidEnterBackground & applicationWillTerminate.

When I put my saving code there, it just doesn't save!

I've tried the following code:

    NSManagedObjectContext *context = [self.coreDataStore contextForCurrentThread];

        [context saveOnSuccess:^{

            NSLog(@"Success!");

        }

        onFailure:^(NSError *error) {

          NSLog(@"Error: %@",error);

}];

It works well when I save immediately, but when this peace of code is in the methods mentioned above, it doesn't print anything!

Not "success" and not "error", and of course that on the web I don't see the new object.

Well, when should I save the changes that are made in my app? Obviously I can't save them anytime there's a change.

Thanks.

Noam Solovechick
  • 1,127
  • 2
  • 15
  • 29
  • Do you have necessity for saving data only in those app delegate methods? What if the app crashes during execution for some random reason after a user adds/updates/deletes something? – swiftcode Jun 02 '13 at 23:06

1 Answers1

0

Solution: In stead of using saveOnSuccess:onFailure:, use saveAndWait:

Noam Solovechick
  • 1,127
  • 2
  • 15
  • 29