Is it possible to extend the swift native Array struct? There's no method on Array to sort by an NSSortDescriptor (bug 27723091 - Everyone go open your own bug on this please!) so I was hoping to do something like this:
extension Array {
func sorted(descriptors: [NSSortDescriptor]) -> [Element] {
return (self as NSArray).sortedArray(using: descriptors)
}
}
But that doesn't work as "Cannot convert value of type 'Array<Element>' to type 'NSArray' in coersion"
Sorry, I have been missing that when Array.Element is a descendent of NSObject, it does not conform to `_ObjectiveCBridgeable`.
You may need another extension like this:
extension Array where Element: NSObject {
func sorted(descriptors: [NSSortDescriptor]) -> [Element] {
return (self as NSArray).sortedArray(using: descriptors) as! [Element]
}
}
I'm not sure these two extensions cover whole use cases of yours. Please tell me how these work, or how these do not work.