I have a class:
class GameManager {...
and within it I have this func:
func startGame() {
msgTimer = Timer(timeInterval: 0.5, target: self, selector: #selector(typeMessage(_:)), userInfo: nil, repeats: true)
}
and the selector it calls:
@objc func typeMessage(_ sender:Timer) {
if textCount > strInitText.characters.count {
let strThisChar = strInitText[strInitText.index(strInitText.startIndex, offsetBy: textCount)]
strDisplayText = strDisplayText + String(strThisChar)
print(strDisplayText)
}
}
But the selector never gets called.
Change
msgTimer = Timer(timeInterval: 0.5, target: self, selector: #selector(typeMessage(_:)), userInfo: nil, repeats: true)
to
msgTimer = Timer.scheduledTimer(timeInterval: 0.5, target: self, selector: #selector(typeMessage(_:)), userInfo: nil, repeats: true)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With