我有一個簡單的標籤文本動畫在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 –