使用关系从核心数据数据库中删除所有表记录 [英] Deleting all table records from core data database using relationship

查看:118
本文介绍了使用关系从核心数据数据库中删除所有表记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用核心数据为我的应用程序,我有4-5个表,其中之一是userProfile表。我已经在应用程序中实现注销。如果用户退出应用程序删除用户配置文件,并将插入新如果与其他用户帐户登录。我想删除所有的记录从数据库中userprofile删除。 im使用关系,但它不会从db删除其他记录,即使用户配置文件记录已删除。
一件事我想提到的是所有的数据来自服务。并且我使用级联删除规则在userprofile表和其他表之间创建关系。

解决方案

您有两种不同的方法来实现这一点。



首先是删除存储并再次创建它。这意味着访问文件系统中的存储,并删除sql文件。例如,您可以在以下讨论中找到如何实现此功能:删除/重置第二个是解决方案是在 UserProfile >实体将链接其他的。在后者中,你必须设置一个反向关系(nullify将是正确的方法)。有关详情,请访问设置核心数据中的父子关系



这样说,根据我的经验,我不鼓励在核心数据中保存用户信息(例如密码) 。相反,采取钥匙串为此。有一些库可以轻松地包装Keychain访问权限(例如 SSKeychain )。


I'm using core data for my application i have 4-5 tables one of which is userProfile table. i have implemented logout in the app. if user logs out of the app im deleting user profile and will be inserting new if logged in with other user account. i want to delete all the records from database on userprofile delete. im using relationship for this but it is not deleting other records from the db even if user profile record has been deleted. one thing i would like to mention is all the data is coming from service. and i am using cascade delete rule for relationship created between userprofile table and other tables.

解决方案

You have two different ways to achieve this.

The first is to delete the store and create it again. This means access the store in the file system and delete the sql file, for example. For example, you can find how to achieve it in the following discussion: Delete/Reset all entries in Core Data?.

The second is solution is to create a cascade relationship in UserProfile entity that will link the other ones. In the latter you must set up an inverse relationship (nullify would be the correct approach). For further info see my answer at Setting up a parent-child relationship in Core Data.

Said this, and based on my experience, I would discourage to save user info (e.g. passwords) in Core Data. Instead, adopt the Keychain for this. There are libraries that wrap the Keychain access in an easy manner (e.g. SSKeychain).

这篇关于使用关系从核心数据数据库中删除所有表记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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