let fileURL = try! FileManager.default.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: false)
.appendingPathComponent("sampleDB.sqlite")
// open database
var db: OpaquePointer?
if sqlite3_open(fileURL.path, &db) != SQLITE_OK {
print("error opening database")
}
Asked
Active
Viewed 258 times
-4

rmaddy
- 314,917
- 42
- 532
- 579

Aditya Malviya
- 1,907
- 1
- 20
- 25
-
1What's your actual question? What issue are you having with the code you posted? – rmaddy May 08 '19 at 17:46
-
I want to access the data inside the .sqlite file and print it, I'm not sure how to do – Aditya Malviya May 08 '19 at 17:51
-
You referenced https://stackoverflow.com/questions/24102775/accessing-an-sqlite-database-in-swift which has a perfect answer – what exactly is unclear? – Martin R May 08 '19 at 17:52
-
Possible duplicate of [Accessing an SQLite Database in Swift](https://stackoverflow.com/questions/24102775/accessing-an-sqlite-database-in-swift) – Martin R May 08 '19 at 17:55
-
Now that you've removed your code, the question is even more "too broad" than it was before. You seem to think Stack Overflow is a free code-writing service. It isn't. – matt May 08 '19 at 17:55
-
I just edited the new code bud! – Aditya Malviya May 08 '19 at 18:57
1 Answers
1
Trying to access a SQLite database by calling actual SQLite C methods is a very confusing and clumsy thing to do. It's much better to use one of the many fine third-party front ends that lets you talk in a natural native Swift way to SQLite.

matt
- 515,959
- 87
- 875
- 1,141
-
-
1Personally I like FMDB (https://github.com/ccgus/fmdb). And here is an example of using it: https://github.com/mattneub/Programming-iOS-Book-Examples/blob/master/bk2ch23p821SQLite/ch36p1077SQLite/ViewController.swift – matt May 08 '19 at 17:50
-
1I just did help you. I gave you good advice and I showed you sample code. I'm not going to write _your_ code for you. – matt May 08 '19 at 17:51