如何创建具有可查询数组属性的核心数据条目? [英] How do I create a core data entry with a queryable array property?

查看:55
本文介绍了如何创建具有可查询数组属性的核心数据条目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个实体,分别是 Issue User ,它们用来表示从服务器传来的数据.在问题和用户之间存在多对多关系,当我从服务器获取问题时,该对象具有一组用户ID.

I have two entities, Issue and User, which I'm using to represent data that comes to me from a server. There's a many-to-many relationship between Issues and Users, and when I get an Issue from the server the object has an array of User IDs.

稍后,当我从服务器获取用户时,我希望能够找到我存储的具有匹配ID的问题.

Later, when I get a User from the server, I want to be able to find the issues that I've stored that have a matching ID.

我一直计划使用一个可转换的属性来存储每个Issue的用户ID.但是,我读过,可变换的属性是不可查询的.真的吗?如果是这样,如何创建可查询的数组属性?

I had been planning to use a transformable property to store the User IDs for each Issue. However, I've read that transformable properties aren't queryable. Is that true? If so, how do I create an array property that is queryable?

推荐答案

您无法查询存储为实体的可转换属性的数组中的条目是正确的.

It is correct that you cannot query for entries in an array that is stored as a transformable attribute of the entity.

一种可能的解决方案是将用户ID列表作为逗号分隔的字符串属性存储在 Issue 实体中,然后按如下所述搜索匹配的ID:从包含ID的字符串中形成NSPredicate.

One possible solution would be to store the list of users IDs as a comma-separated string attribute in the Issue entity, and later search for a matching ID as described here: Form NSPredicate from string that contains id's.

另一种解决方案是在阅读和创建问题时,在第一遍中就已经创建从问题 User 的关系.当您从服务器上收到带有用户ID列表的问题时,您将找到或创建 User 对象并设置关系.

A different solution would be to create the relationships from Issue to User already in the first pass, when reading and creating the issues. When you get an issue from the server with a list of user IDs, you would find or create the User objects and set the relationship.

这篇关于如何创建具有可查询数组属性的核心数据条目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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