I looked at a similar problem in the Shuffle Array Swift 3 post and tried the code from the Answer, but I still get the same error on the same line.
let j = Int(arc4random_uniform(UInt32(countArray - i))) + i
The line above throws the error:
Binary operator '-' cannot be applied to operands of type 'C.IndexDistance' and 'Range C.IndexDistance'
Entire function:
//function used to shuffle imageArray
func shuffle<C: MutableCollection>(_ imageArray: C) -> C where C.Index == Int {
var imageArray = imageArray
var countArray = imageArray.count
for i in [1 ..< countArray] {
countArray = imageArray.count
let j = Int(arc4random_uniform(UInt32(countArray - i))) + i
swap(&imageArray[i], &imageArray[j])
}
return imageArray
}
Revised Code (below) Still Returns Same Error:
Binary operator '-' cannot be applied to operands of type 'C.IndexDistance' and 'Range C.IndexDistance'
//function used to shuffle imageArray
func shuffle<C: MutableCollection>(_ imageArray: C) -> C where C.Index == Int {
var imageArray = imageArray
var countArray = imageArray.count
for i in imageArray.startIndex ..< imageArray.endIndex-1 {
countArray = imageArray.count
let j = Int(arc4random_uniform(UInt32(countArray - i))) + i
swap(&imageArray[i], &imageArray[j])
}
return imageArray
}