The Problem
The official DataStore setup requiresexpect/actual declarations with platform-specific implementations:
- Android needs
Context.filesDir - iOS needs
NSDocumentDirectory - JVM needs
System.getProperty("java.io.tmpdir")or a custom path
androidMain, iosMain, and jvmMain source sets.
The Solution
With FileKit, you can define everything incommonMain:
Complete Example
Here’s a complete setup for a preferences manager:Why databasesDir?
FileKit.databasesDir returns a platform-appropriate location for persistent data:
| Platform | Location |
|---|---|
| Android | App’s internal databases directory |
| iOS | NSDocumentDirectory |
| macOS | ~/Library/Application Support/{bundle-id} |
| JVM | User’s app data directory |