Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/99.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何修复错误:二进制运算符'==';无法应用于类型为';NSExpression.ExpressionType';和'_';_Ios_Swift_Constants_Nsexpression_Swift Keypath - Fatal编程技术网

Ios 如何修复错误:二进制运算符'==';无法应用于类型为';NSExpression.ExpressionType';和'_';

Ios 如何修复错误:二进制运算符'==';无法应用于类型为';NSExpression.ExpressionType';和'_';,ios,swift,constants,nsexpression,swift-keypath,Ios,Swift,Constants,Nsexpression,Swift Keypath,当我遇到一个表示 .KeyPathExpressionType 我说不出是什么原因 . 在 指的是位于 . 当我搜索Google并堆叠“KeyPathExpressionType”时,我什么也找不到。对我来说也是 .ConstantValueExpressionType 我什么也没找到 每一项都是平等比较 comparison.leftExpression.expressionType == .KeyPathExpressionType 及 在下面的代码中,生成一条错误消息: 二进制运

当我遇到一个表示

.KeyPathExpressionType
我说不出是什么原因

.

指的是位于

.
当我搜索Google并堆叠“KeyPathExpressionType”时,我什么也找不到。对我来说也是

.ConstantValueExpressionType
我什么也没找到

每一项都是平等比较

comparison.leftExpression.expressionType == .KeyPathExpressionType

在下面的代码中,生成一条错误消息:

二进制运算符“==”不能应用于“NSExpression.ExpressionType”和“\u1”类型的操作数

当我替换时,错误会消失

comparison.leftExpression.expressionType == .KeyPathExpressionType


这是正确的吗?有人能告诉我这个问题的答案吗?

代码已经过时了Swift 2代码

.KeyPathExpressionType
替换为
.keyPath
并将
替换为
.ConstantValueExpressionType


类型是
NSExpression.ExpressionType
,请阅读不确定,但看起来像
。KeyPathExpressionType
的旧名称。keyPath
。你能试试比较一下吗?leftExpression.expressionType==.keyPath
?是的。这很有效。我实际上输入了“NSExpression.ExpressionType.keyPath”,我使用了“NSExpression.ExpressionType.keyPath”和“NSExpression.ExpressionType.constantValue”,它就工作了。谢谢。您可以省略
NSExpression.ExpressionType
,编译器将推断类型。
comparison.rightExpression.expressionType == .ConstantValueExpressionType
extension NSPredicate {

    /**
        Parses the predicate and attempts to generate a characteristic-value `HomeKitConditionType`.

        - returns:  An optional characteristic-value tuple.
    */
    private func characteristic() -> HomeKitConditionType? {
        guard let predicate = self as? NSCompoundPredicate else { return nil }
        guard let subpredicates = predicate.subpredicates as? [NSPredicate] else { return nil }
        guard subpredicates.count == 2 else { return nil }

        var characteristicPredicate: NSComparisonPredicate? = nil
        var valuePredicate: NSComparisonPredicate? = nil

        for subpredicate in subpredicates {
            if let comparison = subpredicate as? NSComparisonPredicate, comparison.leftExpression.expressionType == .KeyPathExpressionType && comparison.rightExpression.expressionType == .ConstantValueExpressionType {
                switch comparison.leftExpression.keyPath {
                    case HMCharacteristicKeyPath:
                        characteristicPredicate = comparison

                    case HMCharacteristicValueKeyPath:
                        valuePredicate = comparison

                    default:
                        break
                }
            }
        }

        if let characteristic = characteristicPredicate?.rightExpression.constantValue as? HMCharacteristic,
            characteristicValue = valuePredicate?.rightExpression.constantValue as? NSCopying {
                return .Characteristic(characteristic, characteristicValue)
        }
        return nil
    }
comparison.leftExpression.expressionType == .KeyPathExpressionType
comparison.leftExpression.expressionType.rawValue == NSExpression.ExpressionType.keyPath.rawValue
comparison.rightExpression.expressionType == .ConstantValueExpressionType
comparison.rightExpression.expressionType.rawValue == NSExpression.ExpressionType.constantValue.rawValue