Skip to content

Instantly share code, notes, and snippets.

@developer--
Last active June 3, 2022 10:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save developer--/8c1fcbff45e1ecf02f1cd9c9c10edf2b to your computer and use it in GitHub Desktop.
Save developer--/8c1fcbff45e1ecf02f1cd9c9c10edf2b to your computer and use it in GitHub Desktop.
// commonMain
expect class FileUtils {
fun createFile(filePath: String): Boolean
fun deleteFile(filePath: String): Boolean
}
// androidMain
import java.io.File
actual class FileUtils {
actual fun createFile(filePath: String): Boolean {
return File(filePath)
}
actual fun deleteFile(filePath: String): Boolean {
val file = File(path)
return file.deleteRecursively()
}
}
// iosMain
import platform.Foundation.NSFileManager
actual class FileUtils {
actual fun createFile(filePath: String): Boolean {
val fileManager = NSFileManager.defaultManager
return fileManager.createFileAtPath(path = filePath, contents = null, attributes = null)
}
actual fun deleteFile(filePath: String): Boolean {
return NSFileManager.defaultManager.removeItemAtPath(path = filePath, error = null)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment