Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

filter String with empty String in if statement, iOS

I'm working on a custom keyboard. I'm having trouble filtering Strings Array. I want to filter the array only in if statement, I have an array with letters and empty String's. I want to filter Array only in if statement because I want to remove last character, not empty String.

Here is my code:

keyboardKeyStr = ["h", "e", "l", "l", "o", " ", "", "t", "h", "i", "s", "", "i", "s", " ", "m", "y", " ", "", "a", "r", "r", "a", "y", " "]

if range.length == 1 && text.count == 0 {
    print("Delete Button")

    let emptyStr: String? = ""
    keyboardKeyStr = keyboardKeyStr.filter {$0 != emptyStr}
    keyboardKeyStr.removeLast()
    keyboardKeyArr.append(keyboardView.deleteBtn)
    self.keyboardKeyStr.append("")
}
like image 633
Sandrika Janjghava Avatar asked Sep 03 '26 07:09

Sandrika Janjghava


1 Answers

Try this keyboardKeyStr = keyboardKeyStr.filter{ $0 != "" && $0 != " "}

like image 127
Tiago Couto Avatar answered Sep 06 '26 09:09

Tiago Couto



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!