The official Swift client for Convex.
Convex is the backend application platform with everything you need to build your product.
This library lets you create Convex applications that run on iOS and macOS. It builds on the Convex Rust client and offers a convenient Swift API for executing queries, actions and mutations.
If you haven't started a Convex application yet, head over to the Convex iOS quickstart to get the basics down. It will get you up and running with a Convex dev deployment and a basic iOS application that communicates with it using this library.
Also join us on Discord to get your questions answered or share what you're doing with Convex.
In Xcode, add a package dependency pointing to this Github repo. See the quickstart linked above for step-by-step instructions.
The code below shows a few basic patterns for working with the library. See the full documentation for more details.
import ConvexMobile
struct YourData: Decodable {
let foo: String
@ConvexInt
var bar: Int
}
let client = ConvexClient(deploymentUrl: "your convex deployment URL")
let yourData = client.subscribe(to: "your:data", yielding: YourData?.self)
.replaceError(with: nil)
.values
for await latestValue in yourData {
// Do something with the latest `YourData?` value here.
// The loop body will execute each time the "your:data" query result changes.
}
try await client.mutation("your:mutation", with: ["anotherArg": "anotherVal", "anInt": 42])
This library depends on Rust code built in the
convex-mobile
project. If you are working
on changes there or want to incorporate recent changes from that code into this library, you
should clone convex-mobile
and work with this library as a submodule.
In your convex-mobile
clone:
git submodule init
git submodule update
Once you've done that, starting from your convex-mobile
clone:
cd rust/
./build-ios.sh
- Open Xcode
- Open
convex-mobile/ios
That will build the full Rust library and build and bundle new XCFrameworks for target platforms in the ios/
submodule (which points to this repository).
If you just want to work on the Swift side of things, you can just open a checked out version of this repo in Xcode. It should build and run standalone with previously bundled XCFrameworks.