Swift - 如果文本与数组中的任何字符串完全匹配
Swift - If text matches any string in array exactly
我正在尝试查看我的 UITextField.text 是否与数组中的任何字符串完全匹配。当我使用字母时,我需要知道文本是否完全匹配,而不仅仅是包含数组中的元素。
在 if 语句中,我不确定在 'cameraBodies' 之后放置什么来搜索整个数组?
感谢您的帮助
let cameraBodies = ["A","B","C","D","E","F","G","H","I","J","K",
"L","M","N","O","P","Q","R","S","T","U","V",
"W","X","Y","Z","Other"]
if cameraBodyTextField.text != cameraBodies (Here is the problem) {
print("Does not match")
} else {
print("Does match")
}
}
使用if cameraBodies.contains(cameraBodyTextField.text!) { ... }
。
如需更多帮助,请查看此 array contains.
我正在尝试查看我的 UITextField.text 是否与数组中的任何字符串完全匹配。当我使用字母时,我需要知道文本是否完全匹配,而不仅仅是包含数组中的元素。
在 if 语句中,我不确定在 'cameraBodies' 之后放置什么来搜索整个数组?
感谢您的帮助
let cameraBodies = ["A","B","C","D","E","F","G","H","I","J","K",
"L","M","N","O","P","Q","R","S","T","U","V",
"W","X","Y","Z","Other"]
if cameraBodyTextField.text != cameraBodies (Here is the problem) {
print("Does not match")
} else {
print("Does match")
}
}
使用if cameraBodies.contains(cameraBodyTextField.text!) { ... }
。
如需更多帮助,请查看此 array contains.