Swift5和Coredata:按相关实体 - 属性进行排序

发布于 2025-02-12 13:11:15 字数 838 浏览 1 评论 0原文

即使我冒着两次问问题的风险,我太盲目了,看不到:

如何通过相关实体的属性对提取物进行分类。在我的特殊情况下,我有三张桌子:

client< - > clienttocontacts< - >联系人。在列表视图中,我喜欢列出所有由contacs.lastname排序的clienttocontacs。

我该如何通过andDeScriptor进行操作?

到目前为止,这是我的fetchrequest。但是sortDeScriptor丢了错误。

sortDescriptors: [
NSSortDescriptor(keyPath: \ClientsToContacts?.toContacts!.lastName, ascending: true),
NSSortDescriptor(keyPath: \ClientsToContacts?.toContacts!.firstName, ascending: true)
],
predicate: NSPredicate(format: "(toContacts.lastName CONTAINS[cd] %@) OR (toContacts.firstName CONTAINS[cd] %@) OR (toContacts.company CONTAINS[cd] %@) OR (toContacts.department CONTAINS[cd] %@) OR (toContacts.zip CONTAINS[cd] %@)", filter, filter, filter, filter, filter),
animation: .default

到目前为止,谓词正常工作,并过滤了我的结果。只是分类...

感谢您的帮助。 :-)

Even if I run the risk of asking a question twice and I'm too blind to see:

How can I sort a FetchRequest by an Attribute of an related Entity. In my special case, I've got three tables:

Client <-> ClientToContacts <-> Contacts. In a List View I like to list all ClientToContacs sorted by Contacs.lastName.

How can I do it by sortDescriptors?

This is my FetchRequest so far. But the sortDescriptors throw errors.

sortDescriptors: [
NSSortDescriptor(keyPath: \ClientsToContacts?.toContacts!.lastName, ascending: true),
NSSortDescriptor(keyPath: \ClientsToContacts?.toContacts!.firstName, ascending: true)
],
predicate: NSPredicate(format: "(toContacts.lastName CONTAINS[cd] %@) OR (toContacts.firstName CONTAINS[cd] %@) OR (toContacts.company CONTAINS[cd] %@) OR (toContacts.department CONTAINS[cd] %@) OR (toContacts.zip CONTAINS[cd] %@)", filter, filter, filter, filter, filter),
animation: .default

The predicate works fine so far and filters my results. Only sorting...

Thanks for helping. :-)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文