0

I want to use a local database and I'm using fmdb library.

now I want to open my local database but I got this error :

value of type stringByAppendingPathComponet

enter image description here

my code:

func openDatabase() {
    let resourcePath = Bundle.main.resourceURL!.absoluteString
    let dbPath = resourcePath.stringByAppendingPathComponent(dbFileName)
    let database = FMDatabase(path: dbPath)

    /* Open database read-only. */
    if (!database.openWithFlags(1)) {
        print("Could not open database at \(dbPath).")
    } else {
        self.database = database;
    }
}
S.M_Emamian
  • 17,005
  • 37
  • 135
  • 254
  • 1
    @MartinR While that duplicate contains an answer that ultimately gives the OP the proper code, it is not really a duplicate because the other question does not ask about this question's error. In fact, that other question is asking how to translate Objective-C code into Swift. – rmaddy Feb 26 '17 at 16:23
  • What about this one: http://stackoverflow.com/questions/32501627/stringbyappendingpathcomponent-is-unavailable, or this http://stackoverflow.com/questions/39028248/how-to-display-an-image-from-documents-directory-to-uiimageview-in-swift-3. – Martin R Feb 26 '17 at 16:26
  • Even if that particular issue is solved the code won't work due to wrong API `absoluteString` – vadian Feb 26 '17 at 16:46
  • @vadian please answer the question. – S.M_Emamian Feb 26 '17 at 17:00
  • I can't. Read the answers of the duplicate question carefully. They contain the solution, too. – vadian Feb 26 '17 at 17:06
  • This answer http://stackoverflow.com/a/40692832/1187415 (to the "duplicate") shows how to do it. – Martin R Feb 26 '17 at 17:06

0 Answers0