I am migrating my code from Swift 2.3 to Swift 3. Before it was working fine after migrating I am facing not expected contextual result type NSArray Here is my code
func setConfirmedBookingsAfterSorting() {
if let bookings = ContentService.sharedInstance.confirmedBookings {
self.confirmedBookings = (bookings as NSArray).sortedArray(using: [NSSortDescriptor(key: "startTime", ascending: true)])
}
}
The declared type of the method used is
func sortedArray(using sortDescriptors: [NSSortDescriptor]) -> [Any]
, which means the result is implicitly converted to a Swift array.Try this:
This prevents the conversion and maintains the result as an
NSArray
Objective C object.