我有一个简单的标签文本动画在Swift中。 我得到了以下错误:如何解决:类型'字符串'不符合协议'SequenceType'在Swift
Type 'String' does not conform to protocol 'SequenceType'
下面有我的一些代码:
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
与线错误的圣环:inputText
。
另外,你知道每种角色都有不同的颜色吗?
我希望你能帮助我! 提前谢谢!
[String类型不符合协议序列类型(的可能的复制http://stackoverflow.com/questions/36479826/type-string-does -not-conform-to-protocol-sequencetype) – Thilo
@Thilo,我认为它有点不同。 –
请参阅“使用字符”下的示例https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/StringsAndCharacters.html –