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("")
}
text.count == 0withtext.isEmptyandfilter {$0 != emptyStr}withfilter {!$0.isEmpty}and delete thelet emptyStrline. And why do you declareemptyStras an optional but assign an non-optional value?? Don't annotate worse types than the compiler can infer.