func initializeTextinputTraits(textinputTraits: UITextinputTraits) { textinputTraits.keyboardType = .Default}
通常当访问协议的可选属性时,您添加一个问号,但是在分配值时无效(错误:无法分配给此表达式的结果):
textinputTraits.keyboardType? = .Default
协议如下:
protocol UITextinputTraits : NSObjectProtocol { optional var keyboardType: UIKeyboardType { get set }}这是不可能的Swift(还是?).从 ADF thread引用:
总结Optional property requirements,and optional method requirements that return a value,will always return an optional value of the appropriate type when they are accessed or called,to reflect the fact that the optional requirement may not have been implemented.
So it’s no surprise to get optional values easily. However,setting a property requires implementation to be guaranteed.
以上是内存溢出为你收集整理的Swift:设置协议的可选属性全部内容,希望文章能够帮你解决Swift:设置协议的可选属性所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)