Typhoon defaultAssembly () in Swift

I am having trouble implementing defaultAssembly () for my quick application. I need to access one of the dependencies directly from legacy code.

The application is fully integrated into the typhoon - with the initialization of Plist and storyboard.

The first problem was to set the assembly by default, because it is automatically created from plist. In the end, I just made it default after activation. I do not know if it works correctly, but it works.

public override func activate() -> AppAssembly! {
    var instance = super.activate() as! AppAssembly
    instance.makeDefault()
    return instance
}

The real problem is when I get it like this:

var assembly = TyphoonAssembly.defaultAssembly() as! AppAssembly

I get an error message:

Could not cast value of type 'TyphoonBlockComponentFactory' (0x10f78bc40) to 'AppAssembly'

How do I get it? Or did I set the default assembly incorrectly?

Thank you Thomas

+4
1

- , plist.

, , , , ​​ plist, . :

public dynamic func appDelegate() -> AnyObject {
    return TyphoonDefinition.withClass(AppDelegate.self) {
        (definition) in

        definition.injectProperty("assembly", with: self)
    }
}

AppDelegate:

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
     self.assembly.makeDefault()
 }

, - , Swift - . , , :

var factory = TyphoonComponentFactory.defaultFactory()
var something = factory.componentForKey("someKey")

., - .

+3

Source: https://habr.com/ru/post/1606169/


All Articles