Created
February 6, 2020 07:35
-
-
Save M-Miyazako/6177a0c16b4826e684307b79833141f8 to your computer and use it in GitHub Desktop.
# Viewから親のViewControllerを取得する
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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