Created
March 19, 2016 12:21
-
-
Save codelynx/e825b1c4ef34ca91364f to your computer and use it in GitHub Desktop.
Declaring variable to keep UIViewController that conforms to protocol Themeable
This file contains hidden or 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
protocol Themeable { | |
var viewController: UIViewController { get } | |
} | |
extension Themeable where Self: UIViewController { | |
var viewController: UIViewController { return self } | |
} | |
class ThemeableViewController: UIViewController, Themeable {} | |
let themeable: Themeable = ThemeableViewController() | |
// accessing viewController | |
themeable.viewController.view.backgroundColor = UIColor.blackColor() | |
class ThemeableObject: NSObject, Themeable {} // error |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For more information,
http://qiita.com/codelynx/items/30997a4c6f685af4fabc
(In Japanese)