NSPredicate in NSFetchedResultsController doesn't use Category's getter

左心房为你撑大大i 提交于 2019-12-01 22:12:38

问题


I have an attribute with an int_32 property called seconds. In a category, I restate the property as readonly and override the getter to create it from other properties. The issue is when I use

[NSPredicate predicateWithFormat:@"SELF.seconds > %i"];

The predicate does not work because the getter is not called by the predicate. It is called in my other code just fine, just not in the predicate. Anyone know why this would happen or how to get around this problem? (besides recreating NSFetchedResultsController).


回答1:


The predicate is converted into SQL and run on the store. It doesn't run any of your code. As such you can only use the stored value in the data store. No transient attributes, no methods.

If you want to use the attribute in a fetch then you should save the value. This could be done by implementing willSave and having it set the value just before any other value changes are saved.



来源:https://stackoverflow.com/questions/18558421/nspredicate-in-nsfetchedresultscontroller-doesnt-use-categorys-getter

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