NSPredicate Returns No Results with Fetch Request, Works with Array Filtering

梦想与她 提交于 2019-11-30 13:28:59

Hate to say it but the most common cause of these types of problems is simple typos. Make sure that your attribute names and the predicate are the same. Make sure that your property names and the attributes names are the same. If a reference to a property works but a reference to attribute name doesn't there is probably a mismatch.

You could test for the latter by comparing the return of:

[result valueForKey:@"localID"]

... with the return of:

result.localID

If localId is a numerical value, then you should use an NSNumber object in the predicate formation instead of an NSString.

[request setPredicate:[NSPredicate predicateWithFormat:@"localId == %@", 
    [NSNumber numberWithString:localId]]];

NSPredicate format strings automatically quote NSString objects.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!