我将从HomeKit目录中浏览旧代码:创建房屋,配对和控制附件,并在我遇到一个表达式时设置触发器,说
.KeyPathExpressionType
我不能说什么
.
在
中.KeyPathExpressionType
指的是
的左侧.
当我搜索Google和stack 溢出的" 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
这是正确的吗?谁能告诉我启发我这个问题?
代码已过时2代码。
用.keyPath
替换.KeyPathExpressionType
,用.constantValue
.ConstantValueExpressionType
类型是NSExpression.ExpressionType
,请阅读文档