Ich habe eine einfache Label Text Animation in Swift. Und ich habe den folgenden Fehler:Wie zu beheben: Typ 'Zeichenfolge' entspricht nicht Protokoll 'SequenzType' in Swift
Type 'String' does not conform to protocol 'SequenceType'
Unten einige meiner Codes sind:
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
ist die Linie mit der Fehler zum st Ring: inputText
.
Kennst du auch einen Weg für jedes Zeichen, eine andere Farbe zu haben?
Ich hoffe, du könntest mir helfen! Vielen Dank im Voraus!
Mögliche Duplikat [Typ String entspricht nicht Protokoll sequencetype] tun (http://stackoverflow.com/questions/36479826/type-string-does -nicht-konform zum Protokoll-Sequenztyp – Thilo
@Thilo, ich denke, es ist ein bisschen anders. –
Siehe das Beispiel hier unter "Arbeiten mit Zeichen" https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/StringsAndCharacters.html –