samedi 30 avril 2016

Random Number Function Broken In Xcode 7.3 & iOS 9.3.1

After upgrading to Xcode 7.3 my Swift application keeps crashing when I execute a specific function.

For the code below I am told that "the 'var' parameters are deprecated and will be removed in Swift 3". The fix is to delete the var i.e. change "(var list: C)" to "(list: C)" but as soon as this is done I get an error five lines down for "swap(&list[i], &list[j])". I still need to shuffle the names (random draw) but unsure how to fix this?

// Shuffle array function
func shuffle<C: MutableCollectionType where C.Index == Int>(var list: C) -> C {
    let c = list.count
    if c < 2 { return list }
    for i in 0..<(c - 1) {
        let j = Int(arc4random_uniform(UInt32(c - i))) + i
        swap(&list[i], &list[j])
    }
    return list
}

I am guessing this is the main problem with my application.

Currently the app crashes when the shuffle function is called.

The app is available on the apple store here if you need more context: Shell-Out




Aucun commentaire:

Enregistrer un commentaire