Hi all.
Below code works fine, (strText is a defined outside)
func typeLetter1(){
var arrText = Array( strText.characters)
if intCounter < arrText.count {
let randomInterval = Double((arc4random_uniform(8)+2))/100
tmrTimer?.invalidate()
tmrTimer = NSTimer.scheduledTimerWithTimeInterval(randomInterval, target: self,
selector: #selector(ViewController.typeLetter1), userInfo: nil, repeats: false)
lblFirst.text = lblFirst.text! + String(arrText[intCounter])
} else {
tmrTimer?.invalidate()
}
intCounter += 1
}
However when I try to modify it by moving strText to function parameters it does not. What is the correct way to re-write below code ?
func typeLetter1(strText:String){
var arrText = Array( strText.characters)
if intCounter < arrText.count {
let randomInterval = Double((arc4random_uniform(8)+2))/100
tmrTimer?.invalidate()
tmrTimer = NSTimer.scheduledTimerWithTimeInterval(randomInterval, target: self,
selector: #selector(ViewController.typeLetter1(strText)), userInfo: nil, repeats: false)
lblFirst.text = lblFirst.text! + String(arrText[intCounter])
} else {
tmrTimer?.invalidate()
}
intCounter += 1
}
XCode already promps this code is wrong "selector: #selector(ViewController.typeLetter1(strText))" but I could not figure out how to code it correctly.
Thanks in advance...