I have a simple Label Text Animation in Swift. And I got the following error:
Type 'String' does not conform to protocol 'SequenceType'
Below there are some of my codes:
LabelTextAnimation.swift
:
import UIKit
func setTextWithTypeAnimation(inputText: String, interval: NSTimeInterval, label: UILabel) {
label.text = ""
dispatch_async(dispatch_get_global_queue(QOS_CLASS_USER_INTERACTIVE, 0)) {
for character in inputText { // 1
dispatch_async(dispatch_get_main_queue()) {
label.text = label.text! + String(character)
}
NSThread.sleepForTimeInterval(interval)
}
}
}
ViewController.swift
:
import UIKit
class ViewController: UIViewController {
@IBOutlet var label: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
setTextWithTypeAnimation("This is very cool", interval: 0.13, label: label)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
// 1
is the line with the error to the string: inputText
.
Also, do you know a way for each character to have a different color?
I hope you could help me! Thank you in advance!