enumerate is unavailable call the enumerate method

2019-01-27 23:03发布

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
            }
        }
    }

标签: swift ios9
1条回答
Fickle 薄情
2楼-- · 2019-01-27 23:06

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() {
    // ...
}
查看更多
登录 后发表回答