存储但不要将NSManagedObject保存到CoreData? [英] Store But Don't Save NSManagedObject to CoreData?

查看:130
本文介绍了存储但不要将NSManagedObject保存到CoreData?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的应用程序中有一个简短的设置过程,我创建一个NSManagedObject来存储个人的名称和其他细节,但是在此设置期间,我不想保存对象,直到用户在完成结束设置(只是因为它们因为任何原因取消了设置)。

I have a short setup process in my app and I create an NSManagedObject to store name and other details of an individual, however during this setup I don't want to save the object until the user presses 'Done' right at the end of the setup (just incase they cancel the setup for whatever reason).

因此,可以保持对象持有我的信息很短的时间,直到结束

So is it possible to keep hold the object holding my info for a short time until the end of the setup process without actually saving it into CoreData?

感谢。

推荐答案

当您处理CoreData时,所有添加/修改/删除操作都会发生在NSManagedObjectContext中 - 但是在对该上下文调用save之前,更改不会保存到磁盘。

When you are dealing with CoreData, all add/modify/delete actions occur in the NSManagedObjectContext - but changes are not persisted to disk until you call 'save' on that context.

所以答案是肯定的 - 这是你应该得到的行为。如果要添加或修改NSManagedObjects的属性,这些更改将保存在上下文的内存中,但在实际调用save之前不会保存到磁盘。

So the answer is yes - this is the behavior you should already be getting. If you are adding or modifying the properties of NSManagedObjects, these changes are kept in the memory of the context, but are not being saved to disk until you actually call 'save'.

这篇关于存储但不要将NSManagedObject保存到CoreData?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆