我正在尝试在 Swift 3 中采用UITextInputTraits
自定义子类。UIButton
我添加了文档“符号”部分中指定的所有属性:
import UIKit
class TextInputButton: UIButton {
var autocapitalizationType: UITextAutocapitalizationType = .none
var autocorrectionType: UITextAutocorrectionType = .no
var spellCheckingType: UITextSpellCheckingType = .no
var enablesReturnKeyAutomatically: Bool = false
var keyboardAppearance: UIKeyboardAppearance = .default
var keyboardType: UIKeyboardType = .default
var returnKeyType: UIReturnKeyType = .default
var isSecureTextEntry: Bool = false
// (...rest of class implementation omitted...)
但是,当我尝试编译时,isSecureTextEntry
会导致以下错误:
由 setter 为 'isSecureTextEntry' 提供的 Objective-C 方法 'setIsSecureTextEntry:' 与要求的选择器 ('setSecureTextEntry:') 不匹配
如果我使用建议的“修复它”,属性声明将变为:
var @objc(setSecureTextEntry:) isSecureTextEntry: Bool = false
...但现在我得到了三个错误:
预期模式
一行中的连续声明必须用';'分隔
var
(要我在和之间插入分号@objc
),
和:
- 预期声明
实现这一属性的正确方法是什么?