转换为Swift 3后出错(AnyObject不是UIFontDescriptor的子类型)

时间:2017-08-03 19:47:09

标签: ios swift3 anyobject

将我的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()
}

请看一下图片。任何想法如何解决?enter image description here

1 个答案:

答案 0 :(得分:0)

我的猜测是,在Swift 3中,UIFontDescriptor是一个结构。

结构是值类型,而不是对象类型。 (Any,而不是AnyObject。)尝试将其投放到Any而不是AnyObject