使用 Swift 3,我得到了这个,没有任何错误:
private var SessionRunningContext = 0
func addObservers() {
self.session.addObserver(self, forKeyPath: "running", options: .new, context: &SessionRunningContext)
}
func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
let newValue: AnyObject? = change![NSKeyValueChangeKey.newKey] as AnyObject?
switch context! {
case &SessionRunningContext:
// Do something
}
}
但是,当我在 iOS 12 Xcode Beta 上构建它时,我收到一条错误消息:
使用无关的“&”
对于这一行:
case &SessionRunningContext: