2016-11-04 82 views
0

當我從迅速2轉換爲迅速3 ,其現在面臨誤差「曖昧參照構件標」NSKeyValueChangeKey曖昧參考構件標

下面是我的代碼:

class KeyValueChange { 

    fileprivate let change: [String : AnyObject] 

    init(change: [String : AnyObject]) { 
     self.change = change 
    } 

    var kind: NSKeyValueChange? { 
     guard let value = change[NSKeyValueChangeKey.kindKey] as? NSNumber else { 
      return nil 
     } 

     return NSKeyValueChange(rawValue: value.uintValue) 
    } 

    var indexSet: IndexSet? { 
     return change[NSKeyValueChangeKey.indexesKey] as? IndexSet 
    } 

    var new: AnyObject? { 
     return change[NSKeyValueChangeKey.newKey] 
    } 

} 

請詳細說明,因爲在很多地方得到相同的錯誤

在此先感謝

回答

0

在Swift3中,對於change參數,KVO方法observeValue(forKeyPath:of:change:context:)通過[NSKeyValueChangeKey : Any]?。如果你想使用你的KeyValueChange類,你最好適應變化:

class KeyValueChange { 

    private let change: [NSKeyValueChangeKey : Any] 

    init(change: [NSKeyValueChangeKey : Any]) { 
     self.change = change 
    } 

    var kind: NSKeyValueChange? { 

     guard let value = change[NSKeyValueChangeKey.kindKey] as? NSNumber else { 
      return nil 
     } 

     return NSKeyValueChange(rawValue: value.uintValue) 
    } 

    var indexSet: IndexSet? { 
     return change[NSKeyValueChangeKey.indexesKey] as? IndexSet 
    } 

    var new: Any? { 
     return change[NSKeyValueChangeKey.newKey] 
    } 

}