-
Notifications
You must be signed in to change notification settings - Fork 260
Swift Quick Start
jasperblues edited this page Sep 9, 2014
·
33 revisions
let Application = Swift as TheCoursingRiver
//With all the force of a great TyphoonSetting up a Dependency Injection for your Swift application is easy! First, let's bootstrap Typhoon. Create a sub-class of TyphoonAssembly, and define your AppDelegate, as follows:
public class ApplicationAssembly : TyphoonAssembly {
public dynamic func appDelegate() -> AnyObject {
return TyphoonDefinition.withClass(AppDelegate.self) {
(definition) in
definition.injectProperty("assembly", with: self)
}
}
}###Create an entry in your application's plist to register the assembly:
###And now, add the following property to your AppDelegate:
var assembly : ApplicationAssembly?###Now let's perform an Initializer Injection
public dynamic func basicKnight() -> AnyObject {
return TyphoonDefinition.withClass(Knight.self) {
(definition) in
definition.useInitializer("initWithQuest:") {
(initializer) in
initializer.injectParameterWith(self.defaultQuest())
}
}
}
public dynamic func defaultQuest() -> AnyObject {
return TyphoonDefinition.withClass(CampaignQuest.self)
}###Resolve the component from the container as follows:
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
//Code-completion + no 'magic strings'
var knight : Knight = assembly.basicKnight()
// . . continue setting up App
return true
}And we're done!
- The assembly interface can be injected on any class, not just the AppDelegate
- Typhoon can also be manually bootstrapped, by instantiating a TyphoonComponentFactory. Note that in Objective-C you may cast the TyphoonComponentFactory to your Assembly interfaces for code completion and tight IDE integration. Not that in Swift, this is only possible if you inject the assembly onto a component, as shown above.
#User Guide
(Swift user guide coming soon)
- [Types of Injections](Types of Injections)
- [What can be Injected](What can be Injected)
- Modules
- Scopes
- Obtaining Built Components
- [Integration Testing](Integration Testing)
Something still not clear? How about posting a question on StackOverflow.
Get started in two minutes.
Get familiar with Typhoon.
- Types of Injections
- What can be Injected
- Auto-injection (Objective-C)
- Scopes
- Storyboards
- TyphoonLoadedView
- Activating Assemblies
Become a Typhoon expert.
For contributors or curious folks.
