Files
UUVPN/iOS-SwiftUI-Code/GRDB.swift-6.29.3/Documentation/DemoApps/GRDBAsyncDemo
2025-01-28 12:28:03 +08:00
..
2025-01-28 12:28:03 +08:00
2025-01-28 12:28:03 +08:00
2025-01-28 12:28:03 +08:00
2025-01-28 12:28:03 +08:00
2025-01-28 12:28:03 +08:00

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.