ios – Discover a uiviewcontroller from uinavigationcontroller

[ad_1]

I’m attempting to determine a generic strategy to discover a uiviewcontroller which is auto sort casted. At the moment, I do have this.

extension UINavigationController {

    func contoller(ofType sort:AnyClass) -> UIViewController? {
        for controller in self.viewControllers {
            if controller.isKind(of: sort) {
                return controller
            }
        }
        return nil
    }
}

Calling shall be like:

if let controller = self.navigationController?.contoller(ofType: MyController.self) as? MyController{}

That is how I’m able to get controller object and I have to sort solid it additionally.
I’m attempting to determine a approach to do that like as:

if let controller:MyController = self.navigationController?.contoller(ofType: MyController.self){}

In order that I cannot have to do any sort casting.

For this, I’ll have to do some modifications in UINavigationController extension perform.
Want some suggestion for this.

[ad_2]

Leave a Reply