NSFetchedResultsController fetchedObjects 上的 NSPredicate
我有一个 fetchedResultsController ,它正在拉回许多 User
对象。
我与我的 User
对象存在一对多关系,一个 User
与许多称为 sitesToUser
的 Site
对象。
我正在尝试快速过滤我的 [fetchedResultsController fetchedObjects]
,执行以下操作:
NSPredicate *pred = [NSPredicate predicateWithFormat:@"sitesToUser.isActive == 0"];
NSArray *filt = [[self.fetchedResultsController fetchedObjects] filteredArrayUsingPredicate:pred];
但是,filt
数组永远不会返回任何结果。我使用哪个实体属性似乎并不重要,它永远不会在“filt”中返回任何结果。
在上面,isActive
是一个保存为 NSNumber
的 BOOL
。有什么想法吗……?
I have a fetchedResultsController
which is pulling back a number of User
objects.
I have a one to many relationship with my User
object, one User
to many Site
objects called sitesToUser
.
I am trying to filter my [fetchedResultsController fetchedObjects]
quickly, doing:
NSPredicate *pred = [NSPredicate predicateWithFormat:@"sitesToUser.isActive == 0"];
NSArray *filt = [[self.fetchedResultsController fetchedObjects] filteredArrayUsingPredicate:pred];
However, the filt
array never returns any results. It doesn't seem to matter which Entity attribute I use, it never returns any results in 'filt'.
In the above, isActive
is a BOOL
saved as an NSNumber
. Any ideas....?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我明白了这一点。只需添加 ANY 函数,即可返回所有符合条件的“用户”对象:
效果很好!
I figured this out. Simply add the ANY function, to return all 'User' objects that match the criteria:
Works great!
在谓词中添加“ANY”似乎确实有效。 (尽管这对我来说没有多大意义)也许它并不适用于所有情况。如果有人仍然遇到问题,这就是我首先解决它的方法:
到目前为止,这对我有用。
Adding "ANY" to the predicate really seems to work. (Even though it doesn't make much sense to me) maybe it doesn't work for all cases. If somebody still has problems, here's how I solved it in the first place:
this has worked for me so far.