swift - Swift 3 中的 Int 和 Self.Index.Distance 冲突

标签 swift swift3

<分区>

我有:

extension MutableCollection where Index == Int { // shuffle elements of self in place

    mutating func shuffleInPlace() {

        if count < 2 { return } // empty and single-element collections don't shuffle

        for i in 0 ..< count - 1 {
            let j = Int( arc4random_uniform( UInt32( count - i ) ) ) + i
            guard i != j else { continue }
            swap( &self[ i ], &self[ j ] )
            ...

...

我收到错误:

Binary operator Binary operator '..<' cannot be applied to operands of type 'Int' and 'Self.IndexDistance'

有谁知道如何解决这个问题?

最佳答案

试试这个,将 count -1 放在括号中:

for i in 0 ..< (count - 1)

关于swift - Swift 3 中的 Int 和 Self.Index.Distance 冲突,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40333462/

相关文章:

swift - 带有 get 和 set 的选项

ios - 使用选项卡栏 Controller 时是否可以通过按钮打开特定选项卡?

ios - 类型的值没有成员值Swift 3给出错误

ios - 我可以合并多个透明 SCNShape 对象吗?

ios - 如何在自定义初始化程序中快速返回 nil?

swift - 获取周围坐标的最短代码是什么?

ios - AVAudioEngine 的语音识别在录制后阻止声音

swift - 有没有办法定义一个幂为 2(或计算值)的快速枚举

swift - NSProgressIndicator 无法将背景颜色设置为白色

Swift 3 代码隐藏了我的 UIImageView