I have this code to shuffle a string in swift. For some reason it is giving an error in Xcode 7.1 "swapping a location with itself is not supported. I thought it was working ok. Any ideas where I have gone wrong much appreciated!
let selectedWord = word1 // word1 is a string
var chars = Array(selectedWord.characters)
chars.shuffleString()
let shuffledWord = String(chars)
word1 = shuffledWord
extension Array {
mutating func shuffleString() {
for index in 0..<(count - 1) {
let j = Int(arc4random_uniform(UInt32(count - index))) + index
swap(&self[index], &self[j]) // error on this line saying 'swapping a location with itself is not supported'