0

I am attempting to shuffle an array using an shuffle extension. However the compiler is complaining it

Cannot assign value of type '()' to type '[EYPlayer]'

class SomeClass {
    var playerOrder: Array = [EYPlayer]()

    public func shufflePlayerOrder() {
        self.playerOrder = self.playerOrder.shuffle()
    }
}

The shuffle extension looks like:

extension MutableCollection where Index == Int {
    /// Shuffle the elements of `self` in-place.
    mutating func shuffle() {
        // empty and single-element collections don't shuffle
        if count < 2 { return }

        for i in startIndex ..< endIndex - 1 {
            let j = Int(arc4random_uniform(UInt32(endIndex - i))) + i
            if i != j {
                swap(&self[i], &self[j])
            }
        }
    }
}

I believe its asking me to cast the array but I am not sure.

What is the main issue here?

Thanks

zardon
  • 1,601
  • 4
  • 23
  • 46

0 Answers0