I am making my first steps in Swift and got along the first problem. I am trying to pass an array by reference using inout
on an generic function with constraints.
First, my application start point:
import Foundation
let sort = Sort()
sort.sort(["A", "B", "C", "D"])
And here my class with the actual problem:
import Foundation
class Sort {
func sort<T:Comparable>(items:[T]){
let startIndex = 0
let minIndex = 1
exchange(&items, firstIndex: startIndex, secondIndex: minIndex)
}
func exchange<T:Comparable>(inout array:[T], firstIndex:Int, secondIndex:Int) {
// do something with the array
}
}
I am getting the following error in Xcode on the line calling exchange
:
Cannot convert value of type '[T]' to expected argument type '[_]'
Am I missing here something?
Update: Added complete project code.