Skip to content

Instantly share code, notes, and snippets.

@gobozgz
Last active October 8, 2015 06:45
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 gobozgz/9d1b02364f878bc1a026 to your computer and use it in GitHub Desktop.
Save gobozgz/9d1b02364f878bc1a026 to your computer and use it in GitHub Desktop.
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;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment