Created
February 21, 2019 09:52
-
-
Save nil-biribiri/9a7a3e8343e7ee73102b9a27c5c2347d to your computer and use it in GitHub Desktop.
Custom view protocols for CustomView in UIViewController
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
import UIKit | |
public protocol HasCustomView { | |
associatedtype CustomView: UIView | |
} | |
extension HasCustomView where Self: UIViewController { | |
/// The UIViewController's custom view. | |
public var customView: CustomView { | |
guard let customView = view as? CustomView else { | |
fatalError("Expected view to be of type \(CustomView.self) but got \(type(of: view)) instead") | |
} | |
return customView | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment