I am trying to compare to UIViewController in Swift 3 but there is some error
extension UINavigationController
{
func myPopToViewController(viewController:UIViewController, animated:Bool) -> UIViewController? {
var arrViewControllers:[UIViewController] = []
arrViewControllers = self.viewControllers
for vc:UIViewController in arrViewControllers {
if(vc.isKind(of: viewController) ) // This Line gives me error
{
return (self.navigationController?.popToViewController(vc, animated: animated)?.last)!
}
}
return nil
}
}
/Users/varunnaharia/Documents/Projects/appname/appname/Public/UINavigationController+Extra.swift:18:30: Cannot convert value of type 'UIViewController' to expected argument type 'AnyClass' (aka 'AnyObject.Type')
and if try to use
if(vc is viewController)
It gives
/Users/varunnaharia/Documents/Projects/appname/appname/Public/UINavigationController+Extra.swift:18:22: Use of undeclared type 'viewController'
I am calling it through this
self.navigationController?.popOrPopToViewController(viewController: MyUIViewController(), animated: false)
Using UIView in SwiftUI. The process of integrating UIView is almost identical to the one of UIViewController. Namely, the SwiftUI view must conform to the UIViewRepresentable protocol and implement the same set of methods. Here is an example of how we can represent UIActivityIndicatorView in SwiftUI:
The process of integrating a view controller into SwiftUI view hierarchy is next: Declare a SwiftUI view that conforms to UIViewControllerRepresentable. Implement the two required methods makeUIViewController () and updateUIViewController (). Let’s get started and wrap a font picker into a SwiftUI view:
Here is an example of how we can represent UIActivityIndicatorView in SwiftUI: Let’s display the spinner in ContentView: If you run this code, you’ll see the following result: Every SwiftUI view that represents a UIKit view or view controller undergoes following steps that conclude its lifecycle:
The update method allows us to keep UIViewController in sync with SwiftUI state updates. In this example, we leave it empty, as our view controller does not depend on the rest of our SwiftUI app for any data. Finally, in ContentView, show the font picker modal. In SwiftUI, we present modals with the sheet () view modifier.
for viewsController in arrViewControllers
{
if(viewsController.isKind(of: YourControllerClassName.self)){
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With