Array sort function with protocol

Originator:westerhoff
Number:rdar://18852008 Date Originated:2014-10-03
Status:Open Resolved:
Product:iOS Product Version:8.0
Classification: Reproducible:Yes
 
Summary:
When calling the sort function on a Swift array, the app will crash if that sort function has protocol types as its parameters.

Steps to Reproduce:
Run the following code:

protocol ObjectWithInt {
    var i: Int {get}
}
class IntObject: NSObject, ObjectWithInt {
    let i: Int
    init(i: Int) {
        self.i = i
    }
}

var ints = [IntObject(i: 2), IntObject(i: 1), IntObject(i: 3)]
func sortIntsObjects(i1: ObjectWithInt, i2: ObjectWithInt) -> Bool {
    return i1.i < i2.i
}
ints.sort(sortIntsObjects) // this crashes

Version:
Xcode 6.1

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!