Here\'s a typing animation that adds up characters from an Array to the text of a text field at a fixed time interval:
@IBOutlet weak var textFieldMain: UITextFi
Why not do the following:
func deleteLetter() {
if textFieldMain.text != "" {
textFieldMain.text = str.substringToIndex(textFieldMain.text.endIndex.predecessor())
} else {
typingAnimationTimer?.invalidate()
}
}
By the way, if you start your timer with "repeats: true" in fireDeletionTimer()
you don't need to recreate it again and again in deleteLetter()
Also, stringByReplacingOccurrencesOfString()
clears every instance of that letter in your text, not just the last one.