Fix typos in the demo app

This commit is contained in:
Gwendal Roué committed 2026-11-01 21:04:16 +01:00
1 parent 909f7455e6
commit bd7031ec9b
9 files changed
+25 -25

No files matched your search

@@ -18,7 +18,7 @@ struct AppDatabase: Sendable {
/// See <https://swiftpackageindex.com/groue/GRDB.swift/documentation/grdb/databaseconnections>
private let dbWriter: any DatabaseWriter
/// Creates a `AppDatabase`, and makes sure the database schema
/// Creates an `AppDatabase`, and makes sure the database schema
/// is ready.
///
/// - important: Create the `DatabaseWriter` with a configuration
@@ -62,7 +62,7 @@ struct AppDatabase: Sendable {
// MARK: - Database Configuration
extension AppDatabase {
// Uncomment for enabling SQL logging
// Uncomment to enable SQL logging
// private static let sqlLogger = Logger(subsystem: Bundle.main.bundleIdentifier!, category: "SQL")
/// Returns a database configuration suited for `AppDatabase`.
@@ -76,7 +76,7 @@ extension AppDatabase {
// db.add(function: ...)
// }
//
// Uncomment for enabling SQL logging if the `SQL_TRACE` environment variable is set.
// Uncomment to enable SQL logging if the `SQL_TRACE` environment variable is set.
// See <https://swiftpackageindex.com/groue/GRDB.swift/documentation/grdb/database/trace(options:_:)>
// if ProcessInfo.processInfo.environment["SQL_TRACE"] != nil {
// config.prepareDatabase { db in
@@ -114,25 +114,25 @@ extension AppDatabase {
}
}
/// Delete the specified players
/// Deletes the specified players
func deletePlayers(ids: [Int64]) throws {
try dbWriter.write { db in
_ = try Player.deleteAll(db, keys: ids)
}
}
/// Delete all players
/// Deletes all players
func deleteAllPlayers() throws {
try dbWriter.write { db in
_ = try Player.deleteAll(db)
}
}
/// Refresh all players (by performing some random changes, for demo purpose).
/// Refreshes all players (by performing some random changes, for demo purposes).
func refreshPlayers() async throws {
try await dbWriter.write { db in
if try Player.all().isEmpty(db) {
// When database is empty, insert new random players
// When the database is empty, insert new random players
try createRandomPlayers(db)
} else {
// Insert a player
@@ -155,7 +155,7 @@ extension AppDatabase {
}
}
/// Create random players if the database is empty.
/// Creates random players if the database is empty.
func createRandomPlayersIfEmpty() throws {
try dbWriter.write { db in
if try Player.all().isEmpty(db) {
@@ -175,11 +175,11 @@ extension AppDatabase {
// MARK: - Database Access: Reads
// This demo app does not provide any specific reading method, and instead
// gives an unrestricted read-only access to the rest of the application.
// gives unrestricted read-only access to the rest of the application.
// In your app, you are free to choose another path, and define focused
// reading methods.
extension AppDatabase {
/// Provides a read-only access to the database.
/// Provides read-only access to the database.
var reader: any GRDB.DatabaseReader {
dbWriter
}
@@ -9,7 +9,7 @@ struct Player: Equatable {
/// The player id.
///
/// Int64 is the recommended type for auto-incremented database ids.
/// Use nil for players that are not inserted yet in the database.
/// Use nil for players that are not inserted in the database yet.
var id: Int64?
var name: String
var score: Int
@@ -26,7 +26,7 @@ extension AppDatabase {
// Create the AppDatabase
let appDatabase = try AppDatabase(dbPool)
// Populate the database if it is empty, for better demo purpose.
// Populate the database if it is empty, for a better demo.
try appDatabase.createRandomPlayersIfEmpty()
return appDatabase
@@ -24,7 +24,7 @@
"zero" : {
"stringUnit" : {
"state" : "translated",
"value" : "No Player"
"value" : "No Players"
}
}
}
@@ -52,7 +52,7 @@
"zero" : {
"stringUnit" : {
"state" : "translated",
"value" : "0 point"
"value" : "0 points"
}
}
}
@@ -1,6 +1,6 @@
import SwiftUI
struct PlayerEditionView: View {
struct PlayerEditView: View {
@Environment(\.isPresented) var isPresented
@Environment(\.appDatabase) var appDatabase
@State var form: PlayerForm
@@ -36,6 +36,6 @@ struct PlayerEditionView: View {
#Preview {
NavigationStack {
PlayerEditionView(player: .makeRandom())
PlayerEditView(player: .makeRandom())
}
}
@@ -65,7 +65,7 @@ import GRDB
// MARK: - Actions
/// Delete players at specified indexes in `self.players`.
/// Delete players at the specified indexes in `self.players`.
func deletePlayers(at offsets: IndexSet) throws {
let playerIds = offsets.compactMap { players[$0].id }
try appDatabase.deletePlayers(ids: playerIds)
@@ -76,12 +76,12 @@ import GRDB
try appDatabase.deleteAllPlayers()
}
/// Refresh all players (by performing some random changes, for demo purpose).
/// Refresh all players (by performing some random changes, for demo purposes).
func refreshPlayers() async throws {
try await appDatabase.refreshPlayers()
}
/// Perform 50 refreshes in parallel, for demo purpose.
/// Perform 50 refreshes in parallel, for demo purposes.
func refreshPlayersManyTimes() async throws {
try await withThrowingTaskGroup(of: Void.self) { group in
for _ in 0..<50 {
@@ -8,7 +8,7 @@ struct PlayerListView: View {
List {
ForEach(model.players, id: \.id) { player in
NavigationLink {
PlayerEditionView(player: player)
PlayerEditView(player: player)
} label: {
PlayerRow(player: player)
}
@@ -77,7 +77,7 @@ private struct ContentView: View {
.buttonStyle(.borderedProminent)
}
// Hide the title, but set a string anyway in order to avoid
// an odd relayout when player list becomes empty during
// an odd relayout when the player list becomes empty during
// the tornado.
.navigationTitle("")
}
+4 -4
View File
@@ -5,7 +5,7 @@ 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](../../../README.md#installation), and use the demo as an inspiration.
> **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](../../../README.md#installation), and use the demo as inspiration.
The topics covered in this demo are:
@@ -29,15 +29,15 @@ The topics covered in this demo are:
- [Persistence.swift](GRDBDemo/Database/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.
This file instantiates `AppDatabase` instances for the various needs of the project: one database on disk for the application, and in-memory databases for SwiftUI previews.
- [Player.swift](GRDBDemo/Database/Models/Player.swift)
`Player` is a [Record](../../../README.md#records) 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](../../../README.md#codable-records).
`Player` is a [Record](../../../README.md#records) type, able to read and write in the database. It conforms to the standard Codable protocol in order to gain all the advantages of [Codable Records](../../../README.md#codable-records).
- [PlayerListModel.swift](GRDBDemo/Views/PlayerListModel.swift)
`PlayerListModel` is an `@Observable` object that observes the database, displays always fresh values on screen, and performs actions.
`PlayerListModel` is an `@Observable` object that observes the database, always displays fresh values on screen, and performs actions.
`PlayerListModel` is [tested](GRDBDemoTests/PlayerListModelTests.swift).