jeudi 8 octobre 2015

How can I use a blob in xcode 7 and sqlite. I'm using sqlite.swift

I'm trying to get a NSData objet from a Blob to load it into a Web View. I've read the documentation about SQLite.swift (http://ift.tt/1fqIVuD) but I've nothing clear. Please, help me. I think I need a working example.

my code: http://ift.tt/1LmQyLt

import UIKit
import SQLite


class AreaInfoViewController: UIViewController {

    @IBOutlet weak var webView: UIWebView!

    override func viewDidLoad() {
        super.viewDidLoad()
        getAreaPdf(7)
    }

    func getAreaPdf (areaId: Int64) ->NSData {

        var myPdf:NSData

        let dirPaths = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)
        let docsDir = dirPaths[0]
        let databasePath = docsDir.stringByAppendingString("/database.sqlite")

        let path = InitDb()
        let db = try! Connection(path, readonly: true)

        let areas = Table("areas")
        let id = Expression<Int64>("id")
        let name = Expression<String>("name")
        let pdffile = Expression<SQLite.Blob>("pdffile")


        let query = areas.select(id,name,pdffile)
            .filter(id == areaId)
            .limit(1)
        let result = db.prepare(query)
        for row in result {
            print (row[pdffile]) //At this point row[pdffile] is Blob type
        }
        return myPdf;
    }

}

Thanks a lot everyone.

Aucun commentaire:

Enregistrer un commentaire