I am pretty new to iOS and I am currently designing the "Create a new event" page for my app.
Some info:
Coming from a rails background, I am used to doing the following:
However, I don't believe Core Data has an API that allows the developer to create an entity without saving it. Currently, I am doing something like this:
Code to check if Cancel is pressed.
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
if (![[self.navigationController viewControllers] containsObject:self]) {
This is a bit complicated to be honest. Do you guys have a better suggestion?
It actually works as you described Rails working: new objects aren't saved to the persistent store until you commit them (via NSManagedObjectContext's save: method).
See the Creating and Deleting Managed Objects section of the Core Data Programming Guide. Excerpting...
Simply creating a managed object does not cause it to be saved to a persistent store. The managed object context acts as a scratchpad. You can create and register objects with it, make changes to the objects, and undo and redo changes as you wish. If you make changes to managed objects associated with a given context, those changes remain local to that context until you commit the changes by sending the context a save: message. At that point—provided that there are no validation errors—the changes are committed to the store.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With