使用谓词评估

时间:2018-02-01 09:40:29

标签: swift

当我使用predicate.evalute(带:?)时,我遇到了一个错误并且App终止并抛出错误

  

警察我迟到[1005:286399] *由于未捕获的异常'NSUnknownKeyException'终止应用程序,原因:'[`< Police_i_lert_u.UserXML 0x11abf1d90> valueForUndefinedKey:]:此类不是密钥标识符的密钥值编码兼容。   * 第一次抛出调用堆栈:   (0x182b06364 0x181d4c528 0x182b0602c 0x1834ba434 0x183400e20 0x183441698 0x1834412d8 0x100f06c98 0x100f06dc4 0x182ae3f40 0x100f06374 0x100f07218 0x18c01c6b4 0x18c01c634 0x18c0071dc 0x18c01bf28 0x18c677610 0x18c672bc0 0x18c6726a4 0x18c671800 0x18c016f44 0x18bfe7f64 0x18c93d31c 0x18c93f8a8 0x18c9387c0 0x182aae97c 0x182aae8fc 0x182aae184 0x182aabd5c 0x1829cbe58 0x184878f84 0x18c04b67c 0x100f3dc3c 0x1824e856c)   libc ++ abi.dylib:以NSException类型的未捕获异常终止

我的代码:

@objc func addButtonClicked(_ sender: UIButton) {
    alertController.showHUDProgress(message: nil, vc: self)

    let friendId = String(format: "%ld", String(sender.tag))
    let predicate = NSPredicate.init(format: "identifier ==[c] %@", friendId)
    let index = users.indexOfObject(passingTest: { (object, idx, stop) -> Bool in
        return predicate.evaluate(with: object)
    })

    if index != NSNotFound {
        weak var weakSelf = self
        friendModel.setCompletionBlock(success: { (object) -> Void in
            weakSelf?.addFriendDidSuccess(index: index)
        }, failure: { (error) -> Void in
            weakSelf?.addFriendDidFailure(error: error ?? nil)
        })
    }
    else {
        alertController.hideHUDProgress(vc: self)

        var indexMessage: String!

        if isSet {
            if language == "TH" {
                indexMessage = "ไม่พบผู้ใช้"
            }
            else {
                indexMessage = "Index User not found"
            }
        }

        alertController.alertMessage(message: indexMessage, title: nil, vc: self, isCancel: false)
    }
}

请帮我解决问题。

谢谢。

0 个答案:

没有答案