1

I'm building iOS9.3 app with Swift.

I'm trying to connect the PostgreSQL directly, and yes I know usually the most common approach is to create a web api as bridge between apps and server(like MSSQL,PGSQL,MYSQL...), and that is the easy/safe way to do it.

But right now I need to do direct connection, and I already tried several solution as below, but so far there is no luck. Basically these are build from Obj-C(2010~14), and I also have to create Bridging-Header to connect Obj-C and Swift(That is not a problem).

But I'm stuck here. :(

libpq.framework, PGSQLTouch , PGSQLKit-iOS-9.1.1

If I just used "libpq", the error is "libpq-fe.h' file not found".

If I used PGSQLKit the error will be "No such module 'PGClientKit_ios'" event I setup the Build Phases, Framework Search Paths.

have any ideas?

PGClientKit_ios's git>>> "https://github.com/djthorpe/postgresql-kit"

Objective-C Bridging Header

Cœur
  • 37,241
  • 25
  • 195
  • 267
tim_hong
  • 11
  • 5

1 Answers1

0

if anyone still having the same issue like I did, after a long struggled I got a solution!(I was trying to find or modified all kind of the existing "Kits","framework")

I was surprised, what I was looking for, could be so rarely, suddenly very envious those android developer.

The simple step as follow.

  1. Go find a libpq.framework.
  2. You have to create a C type file(because libpq is not Obj-c.) as C API to connect libpq.
  3. After that create a Bridging-Header to connect it.(It Bridging will not generate its own)
  4. Back to the C type file you created
  5. Follow this "PostgreSQL C Language API" tutorial this tutorial saved me a lot of time .(C has been a very far away from me.)
  6. If need, go to Build Settings >> Enable Bitcode >> YES
  7. Make sure test it on the device.

I will post the sample code on git and share the link, after I finish my project.

:) Cheers.

tim_hong
  • 11
  • 5