Last active
November 17, 2015 23:47
-
-
Save Lascorbe/1df77c6a572de46d5d2b to your computer and use it in GitHub Desktop.
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
// Option without self | |
class Foo1 { | |
private let controller: UIViewController = { | |
return UIStoryboard(name: "Main", bundle: nil).instantiateInitialViewController()! | |
}() | |
private lazy var window: UIWindow = { | |
let window = UIWindow(frame: UIScreen.mainScreen().bounds) | |
window.backgroundColor = UIColor.whiteColor() | |
window.makeKeyAndVisible() | |
return window | |
}() | |
init() { | |
} | |
} | |
// First option using self | |
class Foo2 { | |
private let controller: UIViewController = { | |
return UIStoryboard(name: "Main", bundle: nil).instantiateInitialViewController()! | |
}() | |
private lazy var window: UIWindow = { [unowned self] in | |
let window = UIWindow(frame: UIScreen.mainScreen().bounds) | |
window.backgroundColor = UIColor.whiteColor() | |
window.makeKeyAndVisible() | |
window.rootViewController = self.controller | |
return window | |
}() | |
init() { | |
_ = window | |
} | |
} | |
// Second option using self | |
class Foo3 { | |
private let controller: UIViewController = { | |
return UIStoryboard(name: "Main", bundle: nil).instantiateInitialViewController()! | |
}() | |
private let window: UIWindow = { | |
let window = UIWindow(frame: UIScreen.mainScreen().bounds) | |
window.backgroundColor = UIColor.whiteColor() | |
window.makeKeyAndVisible() | |
return window | |
}() | |
init() { | |
setup() | |
} | |
func setup() { | |
self.window.rootViewController = self.controller | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment