Skip to content

Instantly share code, notes, and snippets.

@igorescodro
Last active October 17, 2023 17:28
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 igorescodro/160924e045496d8add55e00878232636 to your computer and use it in GitHub Desktop.
Save igorescodro/160924e045496d8add55e00878232636 to your computer and use it in GitHub Desktop.
override fun shouldPrepopulateDatabase(databaseName: String): Boolean =
!databaseExists(databaseName)
private fun databaseExists(databaseName: String): Boolean {
val fileManager = NSFileManager.defaultManager
val documentDirectory = NSFileManager.defaultManager.URLsForDirectory(
NSLibraryDirectory,
NSUserDomainMask,
).last() as NSURL
val file = documentDirectory
.URLByAppendingPathComponent("$DATABASE_PATH$databaseName")?.path
return fileManager.fileExistsAtPath(file ?: "")
}
private const val DATABASE_PATH = "Application Support/databases/"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment