Skip to content

Instantly share code, notes, and snippets.

@chelseatroy
Last active September 7, 2016 17:17
Show Gist options
  • Save chelseatroy/830ecc8417d37ddc4619fda41f240a24 to your computer and use it in GitHub Desktop.
Save chelseatroy/830ecc8417d37ddc4619fda41f240a24 to your computer and use it in GitHub Desktop.
ViewController Dependency Injection
public class ExampleViewController: UIViewController {
var dependableService: DependableService
@IBOutlet var someTextLabel: UITextLabel!
class func loadFromStoryboard(
dependableService: DependableService) -> ExampleViewController {
let controller = UIStoryboard(name:"Main", bundle:NSBundle(forClass:self))
.instantiateViewControllerWithIdentifier("ExampleViewController")
as! ExampleViewController
controller.dependableService = dependableService
return controller
}
required public init?(coder aDecoder: NSCoder) {
self.dependableService = AppEnvironment.sharedEnvironment.dependableService
super.init(coder:aDecoder)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment