Last active
June 3, 2022 10:37
-
-
Save developer--/8c1fcbff45e1ecf02f1cd9c9c10edf2b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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