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.

Jason Foglia
  • 2,414
  • 3
  • 27
  • 48
  • 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. – Anatoli P Jun 29 '16 at 01: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. – Jason Foglia Jun 29 '16 at 16:22

1 Answers1

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)

Community
  • 1
  • 1
Anatoli P
  • 4,791
  • 1
  • 18
  • 22
  • Finally working! I basically had to build sqlite3.c to an object file then I followed along with this post: http://stackoverflow.com/a/36637270/955831 and this post http://stackoverflow.com/questions/8702302/howto-compile-sqlite3-in-my-c-app and wrote some meaningful code. :) – Jason Foglia Jul 04 '16 at 15:51
  • I posted the solution in another post updated for Swift 3. http://stackoverflow.com/a/38285232/955831 – Jason Foglia Jul 09 '16 at 19:30