🎉 End-of-year Sale! Save 25% when you subscribe today.

SQLite: SwiftUI

Episode #303 • Nov 18, 2024 • Subscriber-Only

Let’s see how to integrate a SQLite database into a SwiftUI view. We will explore the tools GRDB provides to query the database so that we can display its data in our UI, as well as build and enforce table relations to protect the integrity of our app’s state. And we will show how everything can be exercised in Xcode previews.

Previous episode
SQLite: SwiftUI
Next episode
Locked

Unlock This Episode

Our Free plan includes 1 subscriber-only episode of your choice, plus weekly updates from our newsletter.

Sign in with GitHub

Introduction

Brandon

We have now nearly recreated all the functionality we had when interacting directly with the SQLite C library, but this time using GRDB. We can create database connections, create tables, and insert data into the tables. And each step of the way we saw how GRDB provided a nice interface to this functionality, and allowed us to use many of Swift’s powerful features, such as value types and Swift’s Encodable protocol for automatically inserting a first class Swift data type into the database.

Stephen

The only functionality that we haven’t recreated yet is querying the database to get players. This was quite cumbersome when calling the C library directly, so let’s see what GRDB gives us for this, and along the way we will see what it takes to start showing data from our database in a SwiftUI view.

Querying the database


References

Downloads

Sample code

Get started with our free plan

Our free plan includes 1 subscriber-only episode of your choice, access to 64 free episodes with transcripts and code samples, and weekly updates from our newsletter.

View plans and pricing