mirror of
https://github.com/groue/GRDB.swift
synced 2026-11-29 04:24:21 +00:00
FAQ: How do I open a database stored as a resource of my application?
This commit is contained in:
1 parent
9aa629d36e
commit
cfb987e7e3
1 file changed
+3
-3
@@ -2383,12 +2383,12 @@ FAQ
|
||||
```swift
|
||||
let fm = NSFileManager.defaultManager()
|
||||
let documentsURL = try! fm.URLForDirectory(.DocumentDirectory, inDomain: .UserDomainMask, appropriateForURL: nil, create: true)
|
||||
let dbResourceURL = NSBundle.mainBundle().URLForResource("db", withExtension: "sqlite")
|
||||
let dbResourceURL = NSBundle.mainBundle().URLForResource("db", withExtension: "sqlite")!
|
||||
let dbURL = documentsURL.URLByAppendingPathComponent(dbResourceURL.lastPathComponent!)
|
||||
if !fm.fileExistsAtPath(dbURL.path) {
|
||||
if !fm.fileExistsAtPath(dbURL.path!) {
|
||||
try! fm.copyItemAtURL(dbResourceURL, toURL: dbURL)
|
||||
}
|
||||
let dbQueue = DatabaseQueue(dbURL.path)
|
||||
let dbQueue = DatabaseQueue(path: dbURL.path!)
|
||||
```
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user