Swift: Using find() on arrays containing optionals should be supported

Originator:alek.astrom
Number:rdar://17923848 Date Originated:2014-08-06
Status:Open Resolved:
Product:Xcode Product Version:6 beta 5
Classification:Other Bug Reproducible:N / A
 
Summary:
As of beta 5, the find() function cannot be used on arrays containing optionals, because Optional doesn't implement the equatable protocol. This makes one have to loops instead, which requires more code and is ugly as hell.

Example:
let array: [Int?] = [nil, 1, nil, 2]

// Doesn't work
let indexOfTwo = find(array, 2)

// Works but ugly
var indexOfTwo: Int?
for (index, value) in enumerate(array) {
    if value == 2 {
        indexOfTwo = index
    }
}

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!