Skip to content

Instantly share code, notes, and snippets.

@jeandavid
Created December 20, 2021 10:25
Show Gist options
  • Save jeandavid/0b384f947d4e133943b34075bc0e3ed2 to your computer and use it in GitHub Desktop.
Save jeandavid/0b384f947d4e133943b34075bc0e3ed2 to your computer and use it in GitHub Desktop.
Get the parent view controller by using the UIResponder chain
import UIKit
extension UIResponder {
@objc
public var parentViewController: UIViewController? {
return next as? UIViewController ?? next?.parentViewController
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment