Closed acommoner closed 3 years ago
Your code looks ok. This might be bug because of Mixing Swift and Objective-C. Typhoon v4 was reworked to have much better performance, but there is major changes in assemblies. Can you please try same code but all in Objective-C and confirm it works fine then?
Any progress?
Try this. It should work with Typhoon 4.0.4 and Swift 4
// AppDelegate
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
@objc var helloService: HelloService?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
self.helloService!.sayHello()
return true
}
}
// ApplicationAssembly.swift
public class ApplicationAssembly: TyphoonAssembly {
@objc dynamic var coreComponents: CoreComponents!
@objc public dynamic func appDelegate() -> AnyObject {
return TyphoonDefinition.withClass(AppDelegate.self) { definition in
definition!.injectProperty(#selector(getter: AppDelegate.helloService), with: self.coreComponents.helloService())
definition!.scope = TyphoonScope.singleton
} as AnyObject
}
}
// CoreComponents.swift
public class CoreComponents: TyphoonAssembly {
@objc public dynamic func helloService() -> AnyObject {
return TyphoonDefinition.withClass(HelloService.self) { definition in
definition!.scope = TyphoonScope.singleton;
} as AnyObject
}
}
// HelloService.swift
@objc public class HelloService: NSObject {
public func sayHello() {
print("Hello world")
}
}
Getting below error Printing description of configuration: (TyphoonDefinitionBlock) configuration = variable not available
I have encountered similar issues. My solution is similar to @hydra1983.
Some key points:
Closing this issue @acommoner.
We're working on a Pure Swift DI library (easy to migrate from Typhoon) if you like - Pilgrim.
I am trying to modularize my Assembly files per the instructions, but it doesn't seem to be working when I have a base Assembly class written in Objective C that's being accessed by another Assembly written in Swift. The injected assembly isn't nil, but I get a EXC_BAD_ACCESS error when I try to pull anything off of it.
Is this a known limitation, or am I doing something explicitly wrong?
I'm currently using Typhoon v4.0.3. When I was previously using 3.1.6, this seemed to work.
Here is my code for reference:
ObjC Assembly:
Swift Asssembly: