小编Lov*_*röm的帖子

如何修复我的代码中的“重叠访问‘self’,但修改需要独占访问;考虑复制到局部变量”错误?

我无法继续使用我的应用程序,也无法测试运行它,因为我的代码中有问题,我不知道如何修复!这是代码:

import Foundation

extension Array {
    mutating func shuffle() {
        if count < 2 { return }
        for i in 0..<(count - 1) {
            let j = Int(arc4random_uniform(UInt32(count - i))) + i 
            customSwap(a: &self[i], b: &self[j])
        }
    }
}

func customSwap<T>(a:inout T, b:inout T) {
    let temp = a
    a = b
    b = temp
}
Run Code Online (Sandbox Code Playgroud)

xcode ios swift xcode10 swift4.2

4
推荐指数
1
解决办法
1858
查看次数

标签 统计

ios ×1

swift ×1

swift4.2 ×1

xcode ×1

xcode10 ×1