Kapil Godhwani
09/16/2019, 11:27 PM@ThreadLocal
object ServiceLocator {
lateinit var applicationContext: ApplicationContext
val CareApi by lazy { CareZoneApi(PlatformServiceLocator.httpClientEngine) }
val performLogin: PerformLogin
get() = PerformLogin(CareApi)
val loginPresenter: LoginPresenter
get() = LoginPresenter(performLogin, getUserSettings(applicationContext))
}
How do I access the applicationContext
in my iOS app code to assign it a value. The ApplicationContext is my custom class.
PS: Please let me know if this is also not the right place to ask this query.alex009
09/17/2019, 2:16 AMServiceLocator
instance, on iOS it will be ServiceLocator().applicationContext = •••
...to avoid it you can create global function like:
fun setupServiceLocator(context: ApplicationContext) {
ServiceLocator.applicationContext = context
}
and on iOS side it will be:
ServiceLocatorKt.setupServiceLocator(context: •••)
if file named ServiceLocator.kt (name of class with global functions generated from filename)russhwolf
09/17/2019, 4:12 AMServiceLocator()
gives you the ServiceLocator
instance. It looks like an initializer/method call but it’s always returning the same object.ribesg
09/17/2019, 9:02 AMServiceLocator().x
on iOS in this case is identical to ServiceLocator.x
on JVM/Android. I guess it’s this way because of some kind of limitations in the language translation.Kapil Godhwani
09/17/2019, 12:20 PMshared.h
header file in my imported framework, but it doesnt show up when I do import shared
in my Viewcontroller. Which probably means some old shared framework is getting imported. Dont know from where though.Sam
09/17/2019, 12:23 PMTobi
09/18/2019, 9:06 AMServiceLocator
as ThreadLocal
?
I’ve seen this already a couple of time in other examples, but couldn’t figure out the reason 🤔