sabrefm1 sabrefm1 - 3 years ago 121
iOS Question

Getting error's in swift 3 xcode 8

I have converted old Swift code to the new Swift3 in Xcode. Now it is showing these errors in my Swift file:

self.detailViewController = controllers[controllers.count- 1].topViewController as? DetailViewController


Error:


value of type 'UIViewController' has no member 'topViewController'


let sortedTimes = sorted(times!){a,b in a.0.rawValue < b.0.rawValue}


Error:


'sorted' is unavailable: call the sort() method on the collection

Answer Source

The first one could be that your UINavigationController is put in a collection of UIViewControllers. You need to let the compiler know that it is really a UINavigationController.

self.detailViewController = (controllers[controllers.count - 1] as? UINavigationController)?.topViewController as? DetailViewController

The second one is that the sorted function has now become an instance method.

let sortedTimes = times!.sorted { $0.0.rawValue < $1.0.rawValue }
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download