iPhone Core数据:初始化没有上下文的托管对象 [英] iPhone Core Data: Initializing Managed Object without a context

查看:95
本文介绍了iPhone Core数据:初始化没有上下文的托管对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法在上下文之外初始化被管理对象。我基本上试图在一个上下文之外首先分配/ init一个托管对象,然后弄清楚我是否真的想插入对象,然后使用现有的托管对象上下文注入数据存储。

$ b

解决方案

这是可能的,还是会违反Core Data的预期用途?托管对象由上下文管理,因此你不能真正地使用alloc来实现它们,因为它们并不意味着。然而,通过上下文实例化托管对象不会持久化它,直到你在上下文上调用save方法,所以你会有相同的效果使用上下文来实现它,并只有在你弄清楚你真正想使用的对象后保存。


Is there a way to initialize a managed object outside of a context. I'm basically trying to alloc/init a Managed Object outside of a context first, then figure out if I really want to insert the object, and then inject it into the datastore using an existing managed object context.

Is this possible, or does it go against the intended usage of Core Data?

解决方案

Managed Object are "managed" by the context, therefore you cant really instanciate them with alloc since they are not meant to be.However, instantiating a managed object through the context does not persist it until you call save method on the context, so you would have the same effect using the context to instanciate it and only saving after you figure out that you really want to use the object.

这篇关于iPhone Core数据:初始化没有上下文的托管对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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