NSPredicate 不适用于某些对象

NSPredicate is not working on some object

我的数组包含模型,在那个模型中我有 3 个对象,如 String 所说,firstNamelastNameaction

我正在使用以下谓词

let resultPredicate = NSPredicate(format: "lastName CONTAINS [c] %@ OR firstName CONTAINS [c] %@ OR action CONTAINS [c] %@", searchText, searchText, searchText)            
tableDataArray = dataSourceArray.filter { resultPredicate.evaluateWithObject([=10=]) }

如果我根据 firstNamelastName 搜索字符串,它的工作正常。但是,如果我搜索 action 中存在的字符串,则不会进行过滤。 如有任何帮助,我们将不胜感激。

真的很奇怪...我找不到解决办法。但是我找到了不使用谓词来过滤数组的替代方法。

tableDataArray = dataSourceArray.filter {[=10=].firstName.containsString(searchText) || [=10=].lastName.containsString(searchText) || [=10=].action.containsString(searchText) }
//Me to faced some issue, after many article i referred, found the solution

extension yourModelclassName {

    @objc override func value(forKey key: String) -> Any? {
        switch key {
        case "firstName":
            return firstName
        case "lastName":
            return lastName
        default:
            return nil
        }
    }
}

//Please put the given code in your model class like i gave above, it will work fine.