NSFetchedResultsController中的NSPredicate不使用Category的getter [英] NSPredicate in NSFetchedResultsController doesn't use Category's getter

查看:75
本文介绍了NSFetchedResultsController中的NSPredicate不使用Category的getter的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个具有int_32属性的属性,称为秒.在一个类别中,我将该属性重新声明为只读,并覆盖getter以从其他属性创建它.问题是我何时使用

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"];

该谓词不起作用,因为该谓词未调用getter.在我的其他代码中调用它就好了,只是在谓词中没有.任何人都知道为什么会发生这种情况或如何解决这个问题? (除了重新创建NSFetchedResultsController之外).

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).

推荐答案

谓词将转换为SQL并在存储中运行.它不会运行您的任何代码.因此,您只能使用数据存储区中的存储值.没有瞬态属性,没有方法.

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.

如果要在访存中使用该属性,则应保存该值.这可以通过实现willSave并在保存其他任何值更改之前设置它的值来实现.

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.

这篇关于NSFetchedResultsController中的NSPredicate不使用Category的getter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆