How to get class name of parent ViewController in Swift?

后端 未结 7 1902
清歌不尽
清歌不尽 2021-02-07 03:27

Is there any way to get class name of parent VC in present (child) UIViewController? My \'child\' VC (push) has two \'parent\'UIViewControllers, so I w

7条回答
  •  执笔经年
    2021-02-07 04:10

    Add this extension and find parent view by it's type.

    extension UIResponder {
        
        func next(_ type: T.Type) -> T? {
            return next as? T ?? next?.next(type)
        }
        
    }
    

    How to use

    self.next(UIViewController.self)
    

提交回复
热议问题