我有三个全局变量:
i==s-1
我想计算第一个响应者文本字段或文本视图中所选字符的数量。我尝试使用此代码,但它不起作用,因为activeField超出了范围。有没有办法做到这一点?
var activeTextField = UITextField() // stores the last textFieldDidBeginEditing
var activeTextView = UITextView() // stores the last textViewDidBeginEditing
var lastTextKindIsTextView = true // indicates if the last text used is a UITextView
答案 0 :(得分:2)
在if - else
表达式
let activeField : UITextInput
if lastTextKindIsTextView {
activeField = activeTextView
} else {
activeField = activeTextField
}
或没有if - else
let activeField : UITextInput = lastTextKindIsTextView ? activeTextView : activeTextField