如果字符串与UITextField
中的字符相联系,如何简单地从数组中删除字符串?
例如:如果UITextField
包含字母:“ Ap ”,则数组将仅包含“ Ap ple, Ap p, Ap 如此”,但不包括“ Al,Ben,Culo”。
我的数组:
let array = ["Audi", "BMW", "Lamborghini", "Toyota", "Mazda", "McLaren", "Volkswagen", "Ford", "Aston Martin", "Bentley"]
代码:
func setValue() {
if let index = array.index(of: exerciseNameTextField.text!) {
array.remove(at: index)
}
´
}
答案 0 :(得分:0)
You can try:
let result = array.filter { $0.contains(exerciseNameTextField.text!) }