在swift 3.0中工作:
override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?)
{
if context == &MyContext1 {
.........
}
else if context == &MyContext2 {
.........
}
}
但是,由于我有很多条件,如果我使用这样的开关/情况:
override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?)
{
switch context {
case &MyContext1 :
........
case &MyContext2 :
........
}
}
我在无法转换为整数的情况下遇到错误。
声明:
private var MyContext1 = 0
private var MyContext2 = 0
解开 context
时,代码填充了:
private var MyContext1 = 0
private var MyContext2 = 0
func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
switch context! {
case &MyContext1 : break
//
case &MyContext2 : break
//
default: break
}
}