繁体   English   中英

如何修复:类型'String'不符合Swift中的协议'SequenceType'

[英]How to fix: Type 'String' does not conform to protocol 'SequenceType' in Swift

我在Swift中有一个简单的标签文本动画。 我收到以下错误:

类型'String'不符合协议'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

另外,你知道每个角色有不同颜色的方法吗?

我希望你能帮助我! 先感谢您!

而不是for character in inputText {}for character in inputText {}你应该这样做

for character in inputText.characters {}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM