Skip to content

Latest commit

 

History

History
 
 

GRDBDemo

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 

GRDBDemo Application

GRDBDemo demonstrates how GRDB can fuel a SwiftUI application.

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:

  • GRDBDemoApp.swift

    GRDBDemoApp feeds the SwiftUI app 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, and provides methods that read and write.

    AppDatabase is tested.

  • 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.

  • PlayerListModel.swift

    PlayerListModel is an @Observable object that observes the database, displays always fresh values on screen, and performs actions.

    PlayerListModel is tested.

  • PlayersNavigationView.swift

    PlayersNavigationView is the main navigation view of the application. It instantiates a PlayerListModel from the AppDatabase stored in the SwiftUI environment.