swift 3.0在情况开关的情况下,unsafemutablerawpointer



在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
    }
}

相关内容

最新更新