UIKeyInput 键盘类型协议要求不匹配

UIKeyInput keyboard type protocol requirement does not match

我有一个符合 UIKeyInput 协议的 UIView 子类。我想将键盘类型设置为 numberPad。不幸的是,设置此 属性 没有任何作用。

var keyboardType: UIKeyboardType {
    .numberPad
}

编译器通过以下描述警告我:

Property 'keyboardType' nearly matches optional requirement 'keyboardType' of protocol 'UITextInputTraits'

因此,我知道这个属性不是指UIKeyInput协议。 我一直在寻找其他协议或 类 称为 UIKeyInput,但我没有找到。

您有什么其他可能导致此问题的建议吗?

documentation 所示,您应该为此 属性 提供 getter 和 setter。

optional var keyboardType: UIKeyboardType { get set }