Skip to content

Commit

Permalink
Koin from swift (#45)
Browse files Browse the repository at this point in the history
* We can call koin from swift *

 - implementation for #42
 - Resolved the issue, with simple code!!


---------

Co-authored-by: Rodrigo Varela <[email protected]>
  • Loading branch information
nis-ship-it and rodvar authored Nov 14, 2024
1 parent 7432472 commit 6415a67
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 17 deletions.
4 changes: 4 additions & 0 deletions bisqapps/iosClient/iosClient.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
058557D9273AAEEB004C7B11 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 058557D8273AAEEB004C7B11 /* Preview Assets.xcassets */; };
20A247CCB1F22C088748FC4A /* Pods_iosClient.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = BD3DE01D1D7EB5C68F3EDA7B /* Pods_iosClient.framework */; };
2152FB042600AC8F00CF470E /* iosClient.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2152FB032600AC8F00CF470E /* iosClient.swift */; };
609CEB4AB21E643901D61667 /* KoinHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 609CE23ED65204A4441A4BA8 /* KoinHelper.swift */; };
749C8F4E2CCB978300AE196D /* LifecycleAwareComposeViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 749C8F4D2CCB978300AE196D /* LifecycleAwareComposeViewController.swift */; };
7555FF83242A565900829871 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7555FF82242A565900829871 /* ContentView.swift */; };
/* End PBXBuildFile section */
Expand All @@ -20,6 +21,7 @@
058557D8273AAEEB004C7B11 /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = "<group>"; };
2152FB032600AC8F00CF470E /* iosClient.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = iosClient.swift; sourceTree = "<group>"; };
42D80CC24A1D8AFAD4717654 /* Pods-iosClient.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-iosClient.release.xcconfig"; path = "Target Support Files/Pods-iosClient/Pods-iosClient.release.xcconfig"; sourceTree = "<group>"; };
609CE23ED65204A4441A4BA8 /* KoinHelper.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = KoinHelper.swift; sourceTree = "<group>"; };
749C8F4D2CCB978300AE196D /* LifecycleAwareComposeViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LifecycleAwareComposeViewController.swift; sourceTree = "<group>"; };
7555FF7B242A565900829871 /* BisqApp.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = BisqApp.app; sourceTree = BUILT_PRODUCTS_DIR; };
7555FF82242A565900829871 /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -77,6 +79,7 @@
7555FF8C242A565B00829871 /* Info.plist */,
2152FB032600AC8F00CF470E /* iosClient.swift */,
058557D7273AAEEB004C7B11 /* Preview Content */,
609CE23ED65204A4441A4BA8 /* KoinHelper.swift */,
);
path = iosClient;
sourceTree = "<group>";
Expand Down Expand Up @@ -261,6 +264,7 @@
2152FB042600AC8F00CF470E /* iosClient.swift in Sources */,
7555FF83242A565900829871 /* ContentView.swift in Sources */,
749C8F4E2CCB978300AE196D /* LifecycleAwareComposeViewController.swift in Sources */,
609CEB4AB21E643901D61667 /* KoinHelper.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
7 changes: 1 addition & 6 deletions bisqapps/iosClient/iosClient/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,7 @@ struct ComposeView: UIViewControllerRepresentable {
// view for the presenter its using
// it can also work because this is just the main presenter that binds to lifecycle, that we allow
// this hardcoded dependnecy here.
private let presenter: MainPresenter

init() {
let repository = DomainGreetingRepository<DomainGreeting>()
self.presenter = MainPresenter(greetingRepository: repository)
}
private let presenter: MainPresenter = get()

func makeUIViewController(context: Context) -> UIViewController {
return LifecycleAwareComposeViewController(presenter: presenter)
Expand Down
14 changes: 14 additions & 0 deletions bisqapps/iosClient/iosClient/KoinHelper.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import Foundation
import presentation

func get<A: AnyObject>() -> A {
return DependenciesProviderHelper.companion.koin.get(objCClass: A.self) as! A
}

func get<A: AnyObject>(_ type: A.Type) -> A {
return DependenciesProviderHelper.companion.koin.get(objCClass: A.self) as! A
}

func get<A: AnyObject>(_ type: A.Type, qualifier: (any Koin_coreQualifier)? = nil, parameter: Any) -> A {
return DependenciesProviderHelper.companion.koin.get(objCClass: A.self, qualifier: qualifier, parameter: parameter) as! A
}
2 changes: 1 addition & 1 deletion bisqapps/iosClient/iosClient/iosClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import presentation
struct iosClient: App {
init() {
// TODO might need to get away the helper approach in favour of adding koin pods in
PresentationDIHelperKt.doInitKoin()
DependenciesProviderHelper().doInitKoin()
}

var body: some Scene {
Expand Down
Binary file removed bisqapps/kls_database.db
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package network.bisq.mobile.presentation.di

import kotlinx.cinterop.*
import network.bisq.mobile.domain.di.domainModule
import org.koin.core.Koin
import org.koin.core.context.startKoin
import org.koin.core.parameter.parametersOf
import org.koin.core.qualifier.Qualifier

class DependenciesProviderHelper {

fun initKoin() {
val instance = startKoin {
modules(listOf(domainModule, presentationModule))
}

koin = instance.koin
}

companion object {
lateinit var koin: Koin
}

}

@OptIn(BetaInteropApi::class)
fun Koin.get(objCClass: ObjCClass): Any {
val kClazz = getOriginalKotlinClass(objCClass)!!
return get(kClazz, null, null)
}

@OptIn(BetaInteropApi::class)
fun Koin.get(objCClass: ObjCClass, qualifier: Qualifier?, parameter: Any): Any {
val kClazz = getOriginalKotlinClass(objCClass)!!
return get(kClazz, qualifier) { parametersOf(parameter) }
}

This file was deleted.

0 comments on commit 6415a67

Please sign in to comment.