我正在浏览 HomeKit 目录中的旧代码:当我遇到一个表达式时,创建家庭、配对和控制配件以及设置触发器
.KeyPathExpressionType
我不知道是什么
.
在
.KeyPathExpressionType
是指在左侧
.
当我搜索谷歌并堆栈溢出“KeyPathExpressionType”时,我什么也没找到。这是一样的
.ConstantValueExpressionType
我什么也没找到。
这些相等比较中的每一个
comparison.leftExpression.expressionType == .KeyPathExpressionType
和
comparison.rightExpression.expressionType == .ConstantValueExpressionType
在下面的代码中,生成一条错误消息,内容为:
二元运算符“==”不能应用于“NSExpression.ExpressionType”和“_”类型的操作数
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
这个对吗?谁能告诉我这个问题的启发?