Hi friends, I’m troubleshooting what seems to be a...
# multiplatform
t
Hi friends, I’m troubleshooting what seems to be a type issue, when trying to interact with some KMM code in iOS I have a few different KMM gradle modules, which are interdependent. When trying to call these from iOS, there seems to be a casting issue, due to the iOS classes having the framework name prefixed to the class name
So, for example, I have the following on Android:
Copy code
class RoutineViewModel(val context: Context) {

    val driverFactory = DriverFactory(context)

    val databaseHelper = DatabaseHelper(driverFactory)

    val dataSource = AppDataSource(databaseHelper.database)

    val repository = LocalAppRepository(dataSource)

}
This compiles fine. Note that these classes come from a couple of different gradle modules.
But on iOS:
Copy code
class RoutineViewModel {
         
  private let repository: LocalAppRepository
   
  init() {
     
    let driverFactory = DriverFactory()
     
    let databaseHelper = DatabaseHelper(driverFactory: driverFactory)
     
    let dataSource = AppDataSource(database: databaseHelper.database)
     
    self.repository = LocalAppRepository(dataSource: dataSource)
  }
This fails to compile, as it cannot convert`AppDataSource` to expected type
DatabaseAppDataSource
DirverFactory
,
DatabaseHelper
and
AppDataSource
are part of the same
database
gradle module (and ‘database’ swift framework).
LocalAppRepository
is part of the
data
gradle module (and
data
framework)
I’m sure this is just a misunderstanding/misuse of kmm somehow, but I’m not quite sure where I’m going wrong
Ohh OK, I think the problem I’m describing is with ‘transitive dependencies’ in the iOS frameworks. I found this: https://stackoverflow.com/questions/70266716/how-do-transitive-dependencies-in-kmm-and-ios-work Which suggests that you need a sort of ‘umbrella’ gradle module, which you then export as a single framework to iOS