enumerate is unavailable call the enumerate method on the sequence [duplicate]

情到浓时终转凉″ 提交于 2019-11-28 07:41:34

问题


This question already has an answer here:

  • Swift 2.0 : 'enumerate' is unavailable: call the 'enumerate()' method on the sequence 3 answers

Just downloaded Xcode 7 Beta, and come up with this error on enumerate

error:

enumerate is unavailable call the enumerate method on the sequence

 func layoutSpecialKeysRow(row: [Key], keyWidth: CGFloat, gapWidth: CGFloat, leftSideRatio: CGFloat, rightSideRatio: CGFloat, micButtonRatio: CGFloat, isLandscape: Bool, frame: CGRect) -> [CGRect] {
    var frames = [CGRect]()

    var keysBeforeSpace = 0
    var keysAfterSpace = 0
    var reachedSpace = false
    for _k, key) in enumerate(row) {
        if key.type == Key.KeyType.Space {
            reachedSpace = true
        }
        else {
            if !reachedSpace {
                keysBeforeSpace += 1
            }
            else {
                keysAfterSpace += 1
            }
        }
    }

回答1:


In Swift 2, enumerate is not a global function anymore, it's an extension of SequenceType.

Call it directly on the sequence to enumerate like this:

for (index, key) in row.enumerate() {
    // ...
}


来源:https://stackoverflow.com/questions/31230761/enumerate-is-unavailable-call-the-enumerate-method-on-the-sequence

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!