Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Swift Playgrounds & iOS Simulator
import UIKit
struct MainScene {
let vc: UIViewController
let nc: UINavigationController
init(vc: UIViewController) { = vc = UINavigationController(rootViewController: vc)
extension UIViewController {
class func viewController(color: UIColor) -> UIViewController {
let vc = UIViewController()
vc.view = UIView(frame: UIScreen.mainScreen().bounds)
vc.view.backgroundColor = color
return vc
class ButtonHandler: NSObject {
let scene: MainScene
init(scene: MainScene) {
self.scene = scene
func buttonPressed(sender:UIButton) {
println("button pressed")
let vc = UIViewController.viewController(UIColor.yellowColor()), animated: true)
let vc = UIViewController.viewController(UIColor.greenColor())
vc.title = "title"
let button = UIButton.buttonWithType(.System) as UIButton
button.setTitle("press me", forState: UIControlState.Normal)
button.sizeToFit() =
let mainScene = MainScene(vc: vc)
let handeler = ButtonHandler(scene: mainScene)
button.addTarget(handeler, action: "buttonPressed:", forControlEvents: UIControlEvents.TouchUpInside)
//Run playground
let window = UIWindow(frame: UIScreen.mainScreen().bounds)
window.rootViewController =
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment