English 中文(简体)
基于关系内容的预科
原标题:NSPredicate based on content of relationship

我有一个实体 MyEntity , 它有 >tags to-many relations, 所以 tags NSSet , 它是一个可选的, 所以某些 meentitys 没有 tags 。 这里我要做的是:

 predicate= [NSPredicate predicateWithFormat:
 @"(rootId == parentId AND NONE tags.tagName == %@)", @"badTag"];

所以我想要得到所有 MyEnitys rootId = sublicationId 中的所有 MyEnitys 。 如果标签上有一个名为 “badTag” 的标签, 而不给我任何实体。 问题在于如果该实体根本没有任何标签, 那该实体将不会被退回。 我尝试过上述标签的更改 :

 @"(rootId == parentId AND ANY tags.tagName != %@)", @"badTag"];

但结果却是一样的。如果实体没有任何标签,我如何使这一前提发挥作用?

最佳回答

您可以使用 < em> subquery < / em > 的前提来解决这个问题。 一旦掌握了它们, 子类的力量就非常强大。 不幸的是, 它们没有被详细记录下来 。

(rootId == parentId) AND (SUBQUERY(tag, $x, $x.tagName == %@).count() == 0)
问题回答

也许添加一个 OR coUNT(tats) = 0 会得到你想要的?

如果这是 SQL 商店, 请打开 CoreData SQL 调试, 并查看实际运行中的内容 。 < a href=" https:// stackoverflow.com/ questions/64228630/xcode4- 和- count- data- how- en- en- able- sql- debugging" > XCode4 和核心数据: 如何启用 SQL 调试





相关问题
List Contents of Directory in a UITableView

I am trying to list the contents of Ringtones directory in a TableView, however, I am only getting the last file in the directory in ALL cells, instead of file per cell. This is my code: - (...

iPhone NSUserDefaults persistance difficulty

In my app i have a bunch of data i store in the NSUserdefaults. This information consists of an NSObject (Object1) with NSStrings and NSNumbers and also 2 instances of yet another object (Object2). ...

Writing a masked image to disk as a PNG file

Basically I m downloading images off of a webserver and then caching them to the disk, but before I do so I want to mask them. I m using the masking code everyone seems to point at which can be found ...

Resize UIImage with aspect ratio?

I m using this code to resize an image on the iPhone: CGRect screenRect = CGRectMake(0, 0, 320.0, 480.0); UIGraphicsBeginImageContext(screenRect.size); [value drawInRect:screenRect blendMode:...

Allowing interaction with a UIView under another UIView

Is there a simple way of allowing interaction with a button in a UIView that lies under another UIView - where there are no actual objects from the top UIView on top of the button? For instance, ...