(Typhoon creator here).
Typhoon is a dynamic, introspective dependency injection container , and uses the Objective-C run-time. There are the following limitations, when it comes to Swift:
- With Objective-C it avoids magic strings, allowing the use of ordinary IDE refactoring tools, however in Swift selectors are magic strings.
- The Objective-C runtime only provides type information for properties, not method or initializer parameters. So only properties can support auto-wiring of any kind (macros, implicit, etc).
- There is no annotation or macro system for Swift, (but it does have 1st class functions).
You can instruct Typhoon to auto-wire a property in Swift using the following:
public dynamic func appDelegate() -> AnyObject {
return TyphoonDefinition.withClass(AppDelegate.self) {
(definition) in
definition.injectProperty("cityDao")
definition.injectProperty("rootViewController")
}
}
. . and this will match by type, just as the auto-wiring Objective-C macros do. However this does not avoid specifying the name of the property to be injected. There is no other way to do this in Swift. :(
Its worth mentioning there are additional limitations when using Typhoon with Swift:
- "Pure" Swift classes - not extending a Cocoa base class or declaring the
@objc
directive - don't support introspection, dynamic dispatch or dynamic method invocation. Typhoon only works with Cocoa classes.
- Swift protocols require the
@objc
directive.