Evan
06/09/2021, 8:09 PMget
from the KampKit project, but for some objects I get a EXC_BAD_ACCESS
crash. Can anyone point me to what I’m doing wrong? Snippets in comments.Evan
06/09/2021, 8:12 PMlet koinApplication = MySdkKt.initializeSdk(configuration: SdkConfiguration.Builder().baseUrl(baseUrl: "<http://google.com.com>").sessionId(sessionId: "a").customerId(customerId: "a").deviceInfo(deviceInfo: DeviceInfo(platform: "a", platformVersion: "a", deviceDetails: "a", deviceToken: "a")).deviceBlackBox(deviceBlackBox: SwiftBlackBoxProvider()).build())
let config = koinApplication.koin.get(objCClass: BaseConfiguration.self, parameter: "View Controller") as! BaseConfiguration
print(config.customerId)
The above Swift works fine, but if I try to access something I set up in my initializeSdk
method, I get EXC_BAD_ACCESS
Evan
06/09/2021, 8:13 PMlet customerRepo = MySdkKt.sdkKoinApp.koin.get(objCClass: SdkCustomerRepository.self, parameter: "View Controller") as! SdkCustomerRepository //This fails
Evan
06/09/2021, 8:15 PMrusshwolf
06/10/2021, 12:11 AMBaseConfiguration
and SdkCustomerRepository
differ? Is any of the repository access happening from a background thread?Evan
06/10/2021, 4:09 PMsealed class BaseConfiguration(
open val sessionId: String,
open val baseUrl: String,
open val deviceBlackBox: String,
open val deviceInfo: DeviceInfo,
open val loggingEnabled: Boolean,
open val customerId: String,
)
interface SdkCustomerRepository{
suspend fun authenticateSdkCustomer(customerId: String, ssoToken: String):Either<Failure, SdkCustomerResponse>
suspend fun getSdkCustomer(customerId: String, ssoToken: String):Either<Failure, SdkCustomerResponse>
}
class SdkCustomerRepositoryImpl(
private val sdkCustomerApi: SdkCustomerApi,
val locationProvider: LocationProvider
) : SdkCustomerRepository, KoinComponent {
}
They are being set up in a koin module like this:
val sdkModule = module {
single { configuration } //the arguments to the SDK that control how Koin is configured
single { LocationProvider() } //A Wrapper Around Device's Location Services
//some ktor instances used for API's...
single { SdkInitializeApi() }
single<SdkInitializeRepository> { SdkInitializeRepositoryImpl() }
single { SdkCustomerApi(get(), get(qualifier(jsonHttpClientQualifierName))) }
single<SdkCustomerRepository> { SdkCustomerRepositoryImpl(get(), get()) }
}
Both accesses are being made in a viewDidLoad
method, so they should both be from the main thread. I haven’t gotten to the point where threading should be a problem.
The only difference I can really think of is the configuration is being created in swift and passed to the KMP library, while the SdkCustomerRepository
is being instantiated in KMP.
I can access the config from Koin in swift, but neither of the repos in the module snippet above.russhwolf
06/10/2021, 4:20 PMrusshwolf
06/10/2021, 4:21 PMKoinComponent
interface from the repo? You shouldn't need it since you're doing constructor injection, but I also don't see why it would cause a problemEvan
06/10/2021, 4:49 PMEvan
06/10/2021, 5:06 PMThread 1: EXC_BAD_ACCESS (code=1, address=0x31b)
Otherwise things are working fine. If I instantiate Kotlin KMP classes in Swift (things like a interactors/use cases) that lazily load dependencies using by inject()
they work fine.
But there are a few things I’d like to access in the Koin graph directly from Swift…Abhishek Dewan
06/10/2021, 8:51 PMEvan
06/10/2021, 9:53 PMlet repo = MySdkKt.sdkKoinApplication.koin.get(objCProtocol: SdkCustomerRepository.self) as! SdkCustomerRepository
And it resulted in an unrecognized selector crash:
2021-06-10 16:48:22.398739-0500 iosSampleApp[72487:1483526] -[ISSKoin_coreKoin getObjCProtocol:]: unrecognized selector sent to instance 0x600001e41410
2021-06-10 16:48:22.413973-0500 iosSampleApp[72487:1483526] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[ISSKoin_coreKoin getObjCProtocol:]: unrecognized selector sent to instance 0x600001e41410'
*** First throw call stack:
(
0 CoreFoundation 0x00007fff20422fba __exceptionPreprocess + 242
1 libobjc.A.dylib 0x00007fff20193ff5 objc_exception_throw + 48
2 CoreFoundation 0x00007fff20431d2f +[NSObject(NSObject) instanceMethodSignatureForSelector:] + 0
3 CoreFoundation 0x00007fff204274cf ___forwarding___ + 1455
4 CoreFoundation 0x00007fff204297a8 _CF_forwarding_prep_0 + 120
5 MySdk 0x000000010b23a32e $s7MySdk0aB13InitilizationC11viewDidLoadyyF + 2526
Abhishek Dewan
06/10/2021, 11:24 PMEvan
06/10/2021, 11:43 PM