0
我的SWIFT代碼轉換爲SWIFT 3之後我得到了以下錯誤:錯誤
(AnyObject不是UIFontDescriptor的亞型)在我的代碼
public init(controller : UIViewController) {
super.init()
addResponderFromView(controller.view)
}
deinit {
for infoDict in textFieldInfoCache {
let view : AnyObject = (infoDict as AnyObject).object(forKey: kIQTextField)!
if let textField = view as? UITextField {
let returnKeyTypeValue = infoDict[kIQTextFieldReturnKeyType] as! NSNumber
textField.returnKeyType = UIReturnKeyType(rawValue: returnKeyTypeValue.intValue)!
textField.delegate = infoDict[kIQTextFieldDelegate] as! UITextFieldDelegate?
} else if let textView = view as? UITextView {
textView.returnKeyType = UIReturnKeyType(rawValue: (infoDict[kIQTextFieldReturnKeyType] as! NSNumber).intValue)!
let returnKeyTypeValue = infoDict[kIQTextFieldReturnKeyType] as! NSNumber
textView.returnKeyType = UIReturnKeyType(rawValue: returnKeyTypeValue.intValue)!
textView.delegate = infoDict[kIQTextFieldDelegate] as! UITextViewDelegate?
}
}
textFieldInfoCache.removeAllObjects()
}
你爲什麼要繼續將'infoDict'轉換爲'AnyObject'?而且,爲此,爲什麼使用'object(forKey:)'而不是'[「key」]''? – NRitH
你的'infoDict'是什麼類型? – NRitH
AnyObject在Swift 3中總是非常糟糕。關心真實類型 – vadian