I’m currently working on a simple CoreData app for iPad and I’m not exactly sure when I have to explicitly save. I know that there is auto-save; however, I feel that I need to explicitly save in order to make sure my program doesn’t crash. Here’s a brief overview of the program:
~ It’s a form program that presents the user with a set of text fields and segmented controls to fill out. (Think a person filling out a survey, or answering questions about their name, age…etc).
~ Any number of these fields can be filled out. None of them are mandatory.
~ A user can save and load their form at any time and they can have multiple different forms saved at once. They can delete their saved documents
~ I’m currently storing this data using core data where one entity object represents a form. This entity object contains a list of all of the fields which the user has completed and their responses to each field.
~ I also have an NSManagedObject subclass of this entity object. Thus every time a field is filled out I do something such as currentForm.name = textfield.text.
Ok, so my question is, when do I have to explicitly save? If I write code such as currentForm.name = textfield.text does core data perform an immediate save or do I have to explicitly tell it to do so (assuming that I don’t want to wait for the auto-save)? Are there any other times when I might have to save? Do I have to save after I delete a stored document?
Thanks!
Here’s how you save
I would save “early and often” or at least on Notifications for didEnterBackground