mercredi 24 février 2016

Unable to load database with FMDB in swift

I'm trying to create an app with login/signup. I'm using sqlite to save the user information and password. But it's not working since the database isn't being loaded into the code.

            let filemgr = NSFileManager.defaultManager()
            let dirPaths =
            NSSearchPathForDirectoriesInDomains(.DocumentDirectory,
                .UserDomainMask, true)
            var docsDir = dirPaths[0] as! String
            print(docsDir)
            var databasePath = docsDir + "/contacts.sqlite"
            if filemgr.fileExistsAtPath(databasePath as String) {
                let contactDB = FMDatabase(path: databasePath as String)
                if contactDB == nil {
                    print("Error: \(contactDB.lastErrorMessage())")
                }
           //Remaining code
           }

I inserted print (contactDB) right below it's declaration to see what it contains.

2016-02-24 13:27:59.445 Login[12850:1625864] The FMDatabase <FMDatabase: 0x7fd76b804750> is not open.
nil

This is what I got in the console. "Login" is the class name where this code is from. I'm unable to make progress since I'm unable to load the database. Any help is much appreciated. Thanks in advance!

Aucun commentaire:

Enregistrer un commentaire