简体   繁体   中英

Problem with saving with Core Data!

I have an iPhone application, which lets the user add and and modify Assignments. Each Assignment entity is has a relationship with another entity: Course. When the user adds a new Assignment, he has to choose a Course. So far, so good.

But the list of available courses is editable, so while the user is adding an Assignment, he can also create and edit the courses. The problem is, when he saves a new Course, the Assignment is also saved, so even if he then presses cancel at the "Add Assignment" view, the Assignment is alredy saved... Since entities with relationships need to be in the same context, I can't create a new context just for the courses.

Is there any way to save the courses separately?

Instead of throwing away the context when the user hits cancel, just delete the newly created assignment. After deleting the assignment entity, check if there are any changes (meaning the user added courses) and save the context.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM