2

Wanting to give Swift a try and cheaply as possible.

I'm running

  • Ubuntu 16.04
  • SQLite 3.11.0
  • Swift 3.0-dev

All is working, not pretty though, but I'm having a hell of a time connecting to SQLite within Swift.

Has anyone successfully connected and run a query against SQLite with this setup?

While I've seen a bunch of post for iOS solutions I'm not entirely sure these will work on Ubuntu. I wasn't sure if you could or needed to compile Objective-C on Ubuntu.

2
  • 1
    What have you tried so far? If you want to use an Objective-C library intended for Apple platforms, you are likely to run into problems with it on Linux: GCC supports Objective-C as a language, but a lot of libraries and features available on iOS, Mac OSX etc. are not available on Linux. Commented Jun 29, 2016 at 1:13
  • I've got as far as trying to compile Objective-C for the purpose of wrapping the c++ to handle SQLite. That's when boom the compiler threw errors at me. One error was mixedSources and the other was invalidLayout. I feel good that I made it that far, but I feel that's as far as I can go for now. Commented Jun 29, 2016 at 16:22

1 Answer 1

1

Since Objective-C as used on Apple's platforms is not well supported on Linux, I think a better approach might be to access the SQLite C API from Swift by either using a system module or bridging header. You might also want to wrap the SQLite API in a C library exposing a subset of the API that you need in a simplified form more suitable to be called from Swift. You would then invoke the wrapper by creating a system module for it (no system module is needed in this case for the SQLite API) or by using a bridging header.

The following may help:

Compile C code and expose it to Swift under Linux

Linking a C library and its supporting library in Swift (linux)

Sign up to request clarification or add additional context in comments.

2 Comments

Finally working! I basically had to build sqlite3.c to an object file then I followed along with this post: stackoverflow.com/a/36637270/955831 and this post stackoverflow.com/questions/8702302/… and wrote some meaningful code. :)
I posted the solution in another post updated for Swift 3. stackoverflow.com/a/38285232/955831

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.