Using or creating sqlite fb for swift 3

I would like to know how to incorporate a SQLite dB created on my desktop into my swift 3 project. Within the project it is looking at a temporary dB .
Is there a way to either use the desktop dB or copy a version to the temporary path

Just curious, why are you still on Swift 3?

Share and Enjoy

Quinn “The Eskimo!” @ DTS @ Apple

That is the highest version my imac will support.

Would you be able to help me?

That is the highest version my imac will support.

)-:

Most of the standard packages for accessing SQLite from Swift have long since been upgraded to new Swift versions. You may be able to make headway by taking a current package and looking at an old version of it. For example, according to the GRDB read me, version 1.x supports Swift 3.x. @gwendal.roue, feasible is that?

Share and Enjoy

Quinn “The Eskimo!” @ DTS @ Apple

Oh, yes, there is no reason it would not work!

For Swift 3.0 (Xcode 8.2.1 on macOS 10.11), use GRDB v1.0.0.

If you can push to Swift 3.1 (Xcode 8.3.3 on macOS 10.12), use GRDB v1.3.0.

If the database is currently on your desktop, you'll have to make your project able to use it - probably by copying in into your project as a resource. GRDB will then be able to open it:

var configuration = Configuration()
configuration.readonly = true
let dbPath = Bundle.main.path(forResource: "db", ofType: "sqlite")!
let dbQueue = try DatabaseQueue(path: dbPath, configuration: configuration)

See the Usage section of the readme for a quick glimpse at the api.

Thank you for the replies.
I do think I found my problem. It seems that because I run my app in the simulator that the database only exists until the app is finished.

True?

My background is mostly IBM and RPG. I have developed in various other languages: VB6, VB.net, PHP, Javescipt, etc. And I have worked in IT since 1979.

I can set up a section of the app to recreate the db ad tables each so I can test which is not a problem.

Again, thanks for your help.

Have a great day!! stay safe

Don

Thank you for the replies.
I do think I found my problem. It seems that because I run my app in the simulator that the database only exists until the app is finished.

True?

My background is mostly IBM and RPG. I have developed in various other languages: VB6, VB.net, PHP, Javescipt, etc. And I have worked in IT since 1979.

I can set up a section of the app to recreate the db ad tables each so I can test which is not a problem.

Again, thanks for your help.

Have a great day!! stay safe

Don

P.S.
I did see the code you posted but it was difficult to read. smushed together.

Well, we'd need to know where your database is located and how it is accessed from your application.

On iOS, apps are sandboxed, so they can't access the file system freely.

They can only access:

  • Their resources. Those are images, configuration files, localized strings, sqlite database, any kind of read-only data, embedded in the application itself.
  • Files stored in dedicated folders (Documents, Caches, etc.) that you find with the FileManager class. iOS makes sure other apps can't mess with the files created by your app.

It's a pity I can't find an overview document in the Apple doc, because this is a large topic and anyone discovering iOS should be able to quickly learn the basics of the file system.

Anyway. You have to tell how you intend to access your database from your app. If the database file is part of your app and should never change, do make it a resource of your application. Google until you are able to do it. You'll be able to profit from smushed sample codes next after.

Thank you. I really appreciate your reply.
Is it true that when the app is placed on an iphone, that a copy of the database is attached to the app?

One more question. If/when I can release the app for use on the phone, is there code that allows the db to persist on the phone?

Do I need to export the db from my imac to the project. I have tried that and it looks like the structure of the db is exported.

so sorry for the elementary questions, and I appreciate you input.

I suggest you keep on learning the basics of the iOS file system, and especially learn the vocabulary that will help people understand your issues. For example, learn about "resources" and "FileManager", as suggested above. Understand those words. Do use them when appropriate. This will greatly improve the clarity of your questions, and thus the effectiveness of eventual replies, trust me.

Now, for any further questions, please visit Stack Overflow or the Apple Developer forums, which are much better at answering this kind of question than this website. It is dedicated to the Swift language, not about teaching iOS programming. Thank you!

Terms of Service

Privacy Policy

Cookie Policy