https://kotlinlang.org logo
j

jean

03/19/2021, 8:50 AM
I’m trying to get an instance of my sqldelight database on ios, but I haven’t figured it out yet. On android, i do this :
Copy code
val factory = DatabaseDriverFactory(context)
val db = MyDatabase(factory.createDriver())
return NewsDatabaseClient(db)
and it works fine. But if I try this on ios:
Copy code
let factory = DatabaseDriverFactory()
let db = MyDatabase(driver: factory.createDriver())
let client = NewsDatabaseClient(database: db)
I get the following error
'MyDatabase' cannot be constructed because it has no accessible initializers
Does anyone know how I’m suppose to create it?
y

Yev Kanivets

03/19/2021, 8:59 AM
I usually add Kotlin initializer in commonIOS submodule with
NativeSqlDriver
, and then call it from iOS’s ApplicationDelegate. But probably there are better ways for that.
j

jean

03/19/2021, 12:38 PM
I manage to make it work like so :
Copy code
NewsDatabaseClient(
    database:MyDatabaseCompanion.init().invoke(
        driver: DatabaseDriverFactory().createDriver()
    )
)
1
11 Views