Skip to content

Instantly share code, notes, and snippets.

@codelynx
Created March 19, 2016 12:21
Show Gist options
  • Save codelynx/e825b1c4ef34ca91364f to your computer and use it in GitHub Desktop.
Save codelynx/e825b1c4ef34ca91364f to your computer and use it in GitHub Desktop.
Declaring variable to keep UIViewController that conforms to protocol Themeable
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
@codelynx
Copy link
Author

For more information,
http://qiita.com/codelynx/items/30997a4c6f685af4fabc
(In Japanese)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment