Cocoa-Touch,Core Data:如何删除实体的所有对象? [英] Cocoa-Touch, Core Data: How do I delete all objects for an entity?

查看:83
本文介绍了Cocoa-Touch,Core Data:如何删除实体的所有对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,使用Core Data与SQLite存储。



在某些时候,我想删除几个实体的所有对象。可能有接近一千个对象。



从我可以通过google和官方文档可以知道,删除对象的唯一方法是 [managedObjectContext deleteObject:(Entity *)] 。但这意味着我必须首先获取所有对象。



数据存储只是sqlite,是没有办法简单地传递 TRUNCATE TABLE ZENTITY ;

问题是CoreData不只是一个SQLite包装器。

它是一个对象图管理解决方案,它存储您的对象的缓存版本在内存中除了其他东西。就我知道要删除给定的托管对象的所有实例,你必须获取它们,然后删除每个。这不是说这个功能不应该存在,因为它可能应该。


I have an app, using Core Data with a SQLite store.

At some point I'd like to remove all objects for a few entities. There may be close to a thousand objects.

From what I can tell via google and the official docs, the only way to delete objects is to [managedObjectContext deleteObject:(Entity *)] for every object. But this means that I must first fetch all objects.

The data store is just sqlite, is there no way to simply pass a TRUNCATE TABLE ZENTITY; to it?

解决方案

The issue is that CoreData isn't just a SQLite wrapper. It's an object graph management solution and it stores cached versions of your object in memory in addition to other stuff. As far as I know to remove all instances of a given managed object you'll have to fetch them and then delete each. This isn't to say that this functionality shouldn't exist, because it probably should.

这篇关于Cocoa-Touch,Core Data:如何删除实体的所有对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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