diff --git a/core/datastore/src/nativeMain/kotlin/com.jerryokafor.core.datastore/Datastore.native.kt b/core/datastore/src/nativeMain/kotlin/com.jerryokafor.core.datastore/Datastore.native.kt new file mode 100644 index 0000000..14908d8 --- /dev/null +++ b/core/datastore/src/nativeMain/kotlin/com.jerryokafor.core.datastore/Datastore.native.kt @@ -0,0 +1,21 @@ +package com.jerryokafor.core.datastore + +import kotlinx.cinterop.ExperimentalForeignApi +import platform.Foundation.NSDocumentDirectory +import platform.Foundation.NSFileManager +import platform.Foundation.NSURL +import platform.Foundation.NSUserDomainMask + +@OptIn(ExperimentalForeignApi::class) +fun createDataStore(): UserDataStore = + UserDataStore { + val documentDirectory: NSURL? = + NSFileManager.defaultManager.URLForDirectory( + directory = NSDocumentDirectory, + inDomain = NSUserDomainMask, + appropriateForURL = null, + create = false, + error = null, + ) + requireNotNull(documentDirectory).path + "/$dataStoreFileName" + } diff --git a/core/datastore/src/nativeMain/kotlin/com.jerryokafor.core.datastore/Injection.native.kt b/core/datastore/src/nativeMain/kotlin/com.jerryokafor.core.datastore/Injection.native.kt new file mode 100644 index 0000000..99e65ea --- /dev/null +++ b/core/datastore/src/nativeMain/kotlin/com.jerryokafor.core.datastore/Injection.native.kt @@ -0,0 +1,7 @@ +package com.jerryokafor.core.datastore + +import org.koin.dsl.module + +fun nativeUserDatastoreModule() = module { + single { createDataStore() } + }