What is the recommended way to open and close a sqlite db connection with Swift + FMDB?
I'm following this tutorial which suggests that you should open and close a database like:
let db = FMDatabase(path: databasePath as String)
if db.open() {
//do stuff
db.close()
Closing the db outside of a finally block would be a red flag in other languages I've used. I know swift/iOS exception handling is different than most languages and dev environments. But I'm still concerned that this is still a really unsafe way to close the database connection.
Is this method of closing a db actually safe & recommended?
Should I be using something like SwiftTryCatchFinally instead?
let db = FMDatabase(path: databasePath as String)
SwiftTryCatch.try({
connection = db.open()
if connection {
//do stuff
}
}, catch: {
}, finally: {
if connection {
db.close()
}
})
iOS exception handling is so foreign to me :P