Files
Gwendal Roué eeacf93772 Don't mention async sequences in the GRDBAsyncDemo introduction
Been there, done that: when one feeds a SwiftUI view from an async sequence, the view MUST display an initial empty state, until the Swift Concurrency runtime provides the initial value of the sequence. That's why the demo app uses a Combine publisher for feeding views with database value. This commit removes a misleading reference to async sequences.

Fix #1532
2024-04-20 12:40:38 +02:00

3.0 KiB

Async/Await + SwiftUI Demo Application

This demo application is an Async/Await + SwiftUI application. For a demo application that uses UIKit, see GRDBDemoiOS, and for Combine + SwiftUI, see GRDBCombineDemo.

Requirements: iOS 15.0+ / Xcode 13.1+

Note

: This demo app is not a project template. Do not copy it as a starting point for your application. Instead, create a new project, choose a GRDB installation method, and use the demo as an inspiration.

The topics covered in this demo are:

Files of interest:

  • GRDBAsyncDemoApp.swift

    GRDBAsyncDemoApp feeds the app views with a database, through the SwiftUI environment.

  • AppDatabase.swift

    AppDatabase is the type that grants database access. It uses DatabaseMigrator in order to setup the database schema.

  • Persistence.swift

    This file instantiates various AppDatabase for the various projects needs: one database on disk for the application, and in-memory databases for SwiftUI previews.

  • Player.swift

    Player is a Record type, able to read and write in the database. It conforms to the standard Codable protocol in order to gain all advantages of Codable Records.

  • PlayerRequest.swift, AppView.swift

    PlayerRequest defines the player requests used by the app (sorted by score, or by name).

    PlayerRequest feeds the @Query property wrapper (@Query, defined in GRDBQuery, allows SwiftUI views to display up-to-date database content).

    AppView is the SwiftUI view that uses @Query in order to feed its player list.

  • GRDBAsyncDemoTests

    • Test the database schema
    • Test the Player record and its requests
    • Test the PlayerRequest methods that feed the list of players.
    • Test the AppDatabase methods that let the app access the database.