Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swift inject .property of another component doesn't work (has workarounds) #245

Closed
twyneed opened this issue Aug 24, 2014 · 5 comments
Closed

Comments

@twyneed
Copy link

twyneed commented Aug 24, 2014

hi all,

i have to wire an instance created by a singleton CBLManager.sharedInstance(). I tried to adapt your guideline "[Injecting objects produced by other components](Injecting objects produced by other components)" but somehow i didn't get it to work. No error is thrown, just the dbManger component is nil in the localStorageService.

I also tried the valueForKey(key) approach definition.injectProperty("dbManager", with: self.valueForKey("dbManagerFactory").property("sharedInstance")) but this just gives me an
this class is not key value coding-compliant for the key sharedInstance error

As a workaround i placed the CBLManager.sharedInstance() call directly in the definition. definition.injectProperty("dbManager", with: CBLManager.sharedInstance()). Doesn't feel right and i'm not sure if this is causing any other problems but at least the dbManager is set

Assembly.swift

//Component requires Singelton instance for injection
public func localStorageService() -> AnyObject {
      var definitionBlock : TyphoonDefinitionBlock = {(definition : TyphoonDefinition!) in
      definition.scope = TyphoonScopeSingleton
      definition.injectProperty("dbManager", with: self.dbManagerFactory().property("sharedInstance"))}
      return TyphoonDefinition.withClass(MYLocalStorageService.classType(), configuration: definitionBlock)
}

//Factory/Singleton
public func dbManagerFactory() -> AnyObject {
    return TyphoonDefinition.withClass(getClass("CBLManager"))
}
@alexgarbarev
Copy link
Contributor

Hi, @RobbieBubble your code seems to be right. Looks like our "property" feature doesnt work for Swift assmebly. Can you try next code:

public func dbManagerFactory() -> AnyObject {
    var definitionBlock : TyphoonDefinitionBlock = {(definition : TyphoonDefinition!) in
        definition.userInitializer("sharedInstance")
    return TyphoonDefinition.withClass(CBLManager.classType(), configuration: definitionBlock)
}

@twyneed
Copy link
Author

twyneed commented Aug 25, 2014

@alexgarbarev
thx a lot!
this definition works

according injection code
Assembly.swift

 definition.injectProperty("dbManager", with: self.valueForKey("dbManagerFactory"))

@jasperblues jasperblues changed the title Swift Typhoon singelton assembly Swift inject .property of another component doesn't work (has workarounds) Aug 26, 2014
@jasperblues
Copy link
Member

@RobbieBubble Instead of using value for key, try declaring the method with the dynamic attribute. Works great.

@jasperblues
Copy link
Member

Let's retest for Typhoon 3.1 and Swift 1.2

@etolstoy
Copy link
Contributor

etolstoy commented Feb 5, 2017

Closing due to inactivity. If you still experience this issue, feel free to reopen it.

@etolstoy etolstoy closed this as completed Feb 5, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants