Trouble Importing PostgresNIO

I've been trying for the past few days to use the PostgresNIO library onto my swift project. I'm new to Xcode and Swift so I might be missing something, but I keep getting errors when trying to import into my project telling me that the module I'm importing doesn't exist. Could I get some help with this?

What does your package.swift look like?

It looks like you're using an Xcode project (and not a Package.swift) and it also looks like you already added postgres-nio as a package dependency.

I reckon what you're missing is to tell Xcode that your target wants to have the PostgresNIO target. It's a bit hidden in Xcode but here's how you do that:

and then in the menu that pops up after clicking + do this

If you have multiple targets, you'll need to explicitly add this dependency for every target where you need it.

This is quite easy to miss because when you first add your package, then in the wizard, Xcode asks you

so normally, it asks you in the wizards which targets you want to add the dependency to. But what can happen is that at the time when you added the package, the target that you now what the dependency in wasn't there yet, so Xcode didn't add it when you added the package dependency. And that's why you'll now need to add it to the target manually.

Hope that makes sense.

@0xTim This is how my package.swift looks like. Tried playing around with it but I ended up assuming that I didn't need it since the library Postgres-nio already has a package.swift

@johannesweiss Unfortunately, Postgres was already on that list for the target that I wanted. I tried removing it and re-adding it in case it was just being finicky, but that didn't seem to be the case.

The Package.swift in your Xcode project won’t really do anything, best to remove it. If you have an Xcode project, you don’t use Package.swift.

Could you send all the build errors? Go to the rightmost navigator (think it’s called Issue Navigator), then sort by time, take the Build one and send all the errors. The PostgresNIO may only be a followup error. It shows 4 errors in total, we’ll need all of them.

@johannesweiss Thank you for that :) I'll remove that package.swift file.

Yeah, these are the errors I'm getting from Xcode. I'm not sure what the integrity error means.

Ahh, sorry I missed that this is for iOS. The key error is

The package product 'Crypto' requires minimum platform version 13.0 ...".

@0xTim you'll need to add a .iOS(.v13) to the Package.swift in postgres-nio too, much like this one.

@JohnVillalta01 if you don't want to wait for Vapor to release an updated postgres-nio, you could make a local version of this package and add .iOS(.v13) to the Package.swift in your local postgres-nio. Docs how to do the local package here. But once Vapor puts that in theirs, you should be good as you are right now.

1 Like

I think this was definitely a step in the right direction but now I'm facing other errors after placing the local version in the project navigator.

Can you post your edited PostgresNIO Package.swift?

Yeah here's the picture of how my PostgresNio package is looking.

You're missing a , (comma) after .iOS(.v13). You may want to file a bug at bugs.swift.org , it should really give you better diagnostics here.

1 Like

PR is up for postgres-nio: Add platform requirements for iOS, watchOS and tvOS by fabianfett · Pull Request #154 · vapor/postgres-nio · GitHub

1 Like
Terms of Service

Privacy Policy

Cookie Policy