ios - 如果文本字段是 myTextField { 条件 }

标签 ios swift uitextfield

我们有办法在 Swift 中做到这一点吗?

var myTextfield: UITextfield

if textfield is myTextField {
   condition
}

我尝试过但失败了:

if UITextfield = myTextField
if textfield = myTextField
if UITextfield.type = myTextField

还尝试过“==”作为比较运算符。

最佳答案

来自Apple Documentation :

Swift also provides two identity operators (=== and !==), which you use to test whether two object references both refer to the same object instance.

关于ios - 如果文本字段是 myTextField { 条件 },我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32973014/

相关文章:

ios - 如何检查 UITextField 何时发生变化?

ios - UICollectionView 单元格用户交互已禁用

iphone - iOS:在后台同时运行应用程序音频和电话音乐音频

c# - Xamarin.iOS NSUnknownKeyException 原因 : [ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key staticDataSource

ios - 每次调用都很简单的方法分配内存而不释放内存

ios - 如何在关闭并重新打开应用程序时将导航堆栈上的当前 View 和所有以前的 View 显示为 "save"?

ios - ios 中的自动完成文本字段

javascript - iOS html 应用程序 : big scrolling list causes elements to disappear

javascript - 如何突出显示 UIWebView 中第一次出现的字符串?

ios - 颜色属性在 UITextField 中与 NSAttributedString 保持一致