Swift5和Coredata:按相关实体 - 属性进行排序
即使我冒着两次问问题的风险,我太盲目了,看不到:
如何通过相关实体的属性对提取物进行分类。在我的特殊情况下,我有三张桌子:
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论