Skip to content

Instantly share code, notes, and snippets.

@M-Miyazako
Created February 6, 2020 07:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save M-Miyazako/6177a0c16b4826e684307b79833141f8 to your computer and use it in GitHub Desktop.
Save M-Miyazako/6177a0c16b4826e684307b79833141f8 to your computer and use it in GitHub Desktop.
# Viewから親のViewControllerを取得する
extension UIView {
func parentViewController() -> UIViewController? {
var parent: UIResponder? = self
while let next = parent?.next {
if let viewController = next as? UIViewController {
return viewController
}
parent = next
}
return nil
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment