Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
James Lambert
Courses Plus Student 14,477 PointsIs there any help out there for someone trying to use sqlite with swift?
I currently have a working Objective-c app that uses a sqlite database. Really need help with getting swift to use the libsqlite3.dylib.
Can anyone point me in the right direction?
Would love to see a tutorial on this.
4 Answers
Stone Preston
42,016 Pointsmost of the time you dont connect directly to the database itself (is this what you are trying to do?). Generally you create a web based API using PHP or something that fetches things from the DB and returns them to you in JSON, XML, etc
Here is a tutorial that covers building a an app with swift that uses a PHP web service to connect to a MySQL DB
James Lambert
Courses Plus Student 14,477 PointsManisha, The only place I have found to answer this is in a book by Neil Smyth called iOS 7 App Development. It's available through amazon. He is the only one who has a working example for reading a sqlite from an app in objective-c. In the iOS 8 version of the book he uses swift.
If I had it to do over again I would follow the lessons learned in the weather app lesson here in Treehouse. The way they taught me how to serialize json, is a much better approach. You can have the database export to json and then have the app read the information from a web server. That's the way I would do it.
If you follow the Neil Smyth book, the biggest way I messed up was when I imported the database file into the Xcode project. follow his directions exactly.
Stone Preston
42,016 Pointssee this stack overflow post. you can import the library using a bridging header
to create a briding header you can go to file -> new -> objective -c file -> after you finishing creating the file it will ask if you want to create a bridging header. select yes. you can remove the .m file after creating the bridging header
James Lambert
Courses Plus Student 14,477 PointsDid that. Thanks. Still struggling with it. Don't understand why there is so little documentation on the subject. Unless I am wrong this is the only way to use a database in iOS.
James Lambert
Courses Plus Student 14,477 Pointssolved my issue.
The only way to do this is by using a wrapper and an Objective-c bridging header.
If any one wants to know more I can help.
Manisha Parmar
39 PointsHi James,
I am developing a small master detail app using Objective-C, Sqlite. I am stuck with fetching data in detailview based on the row selected in Master view. Could you please help me in this?
Scott Brown
4,406 PointsMe. I'd like to know please. I want to at least print data retrieved via SELECT FROM WHERE etc. I'm using FMDB.
James Lambert
Courses Plus Student 14,477 PointsJames Lambert
Courses Plus Student 14,477 PointsThanks. I'll work through that.