From cdc0131369513f8a7e54fdb295e92e3e3f7d5235 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Sat, 20 Jul 2024 14:38:14 +0200 Subject: [PATCH] Modernize demo apps: iOS 17+ GRDBQuery 0.9.0 #Preview macro --- .../GRDBAsyncDemo.xcodeproj/project.pbxproj | 6 ++-- .../xcshareddata/swiftpm/Package.resolved | 4 +-- .../GRDBAsyncDemo/GRDBAsyncDemoApp.swift | 20 ++++--------- .../GRDBAsyncDemo/PlayerRequest.swift | 28 +++---------------- .../GRDBAsyncDemo/Views/AppView.swift | 22 +++++++-------- .../Views/PlayerCreationView.swift | 8 +++--- .../Views/PlayerEditionView.swift | 14 +++++----- .../GRDBAsyncDemo/Views/PlayerFormView.swift | 23 +++++++-------- .../GRDBAsyncDemo/Views/PlayerList.swift | 18 ++++++------ .../PlayerRequestTests.swift | 4 +-- .../GRDBCombineDemo.xcodeproj/project.pbxproj | 4 +++ .../xcshareddata/swiftpm/Package.resolved | 4 +-- .../GRDBCombineDemo/GRDBCombineDemoApp.swift | 20 ++++--------- .../GRDBCombineDemo/PlayerRequest.swift | 28 +++---------------- .../GRDBCombineDemo/Views/AppView.swift | 22 +++++++-------- .../Views/PlayerCreationView.swift | 8 +++--- .../Views/PlayerEditionView.swift | 14 +++++----- .../Views/PlayerFormView.swift | 23 +++++++-------- .../GRDBCombineDemo/Views/PlayerList.swift | 18 ++++++------ .../PlayerRequestTests.swift | 4 +-- .../GRDBDemoiOS.xcodeproj/project.pbxproj | 4 +++ 21 files changed, 126 insertions(+), 170 deletions(-) diff --git a/Documentation/DemoApps/GRDBAsyncDemo/GRDBAsyncDemo.xcodeproj/project.pbxproj b/Documentation/DemoApps/GRDBAsyncDemo/GRDBAsyncDemo.xcodeproj/project.pbxproj index ceb3cb987..7b04e5beb 100644 --- a/Documentation/DemoApps/GRDBAsyncDemo/GRDBAsyncDemo.xcodeproj/project.pbxproj +++ b/Documentation/DemoApps/GRDBAsyncDemo/GRDBAsyncDemo.xcodeproj/project.pbxproj @@ -354,6 +354,7 @@ BUNDLE_LOADER = "$(TEST_HOST)"; CODE_SIGN_STYLE = Automatic; INFOPLIST_FILE = GRDBAsyncDemoTests/Info.plist; + IPHONEOS_DEPLOYMENT_TARGET = 17.0; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/Frameworks", @@ -373,6 +374,7 @@ BUNDLE_LOADER = "$(TEST_HOST)"; CODE_SIGN_STYLE = Automatic; INFOPLIST_FILE = GRDBAsyncDemoTests/Info.plist; + IPHONEOS_DEPLOYMENT_TARGET = 17.0; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/Frameworks", @@ -512,7 +514,7 @@ DEVELOPMENT_TEAM = ""; ENABLE_PREVIEWS = YES; INFOPLIST_FILE = GRDBAsyncDemo/Info.plist; - IPHONEOS_DEPLOYMENT_TARGET = 15.0; + IPHONEOS_DEPLOYMENT_TARGET = 17.0; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/Frameworks", @@ -534,7 +536,7 @@ DEVELOPMENT_TEAM = ""; ENABLE_PREVIEWS = YES; INFOPLIST_FILE = GRDBAsyncDemo/Info.plist; - IPHONEOS_DEPLOYMENT_TARGET = 15.0; + IPHONEOS_DEPLOYMENT_TARGET = 17.0; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/Frameworks", diff --git a/Documentation/DemoApps/GRDBAsyncDemo/GRDBAsyncDemo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/Documentation/DemoApps/GRDBAsyncDemo/GRDBAsyncDemo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index 5a507d565..216295601 100644 --- a/Documentation/DemoApps/GRDBAsyncDemo/GRDBAsyncDemo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/Documentation/DemoApps/GRDBAsyncDemo/GRDBAsyncDemo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -5,8 +5,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/groue/GRDBQuery", "state" : { - "revision" : "aefc0d7e7a64e841da33e1c8be7429da1bd9b5d6", - "version" : "0.6.0" + "revision" : "a6c46dd38ecf11a5c37732870dc03a384d582fba", + "version" : "0.9.0" } } ], diff --git a/Documentation/DemoApps/GRDBAsyncDemo/GRDBAsyncDemo/GRDBAsyncDemoApp.swift b/Documentation/DemoApps/GRDBAsyncDemo/GRDBAsyncDemo/GRDBAsyncDemoApp.swift index 0ddda97f5..748b10a90 100644 --- a/Documentation/DemoApps/GRDBAsyncDemo/GRDBAsyncDemo/GRDBAsyncDemoApp.swift +++ b/Documentation/DemoApps/GRDBAsyncDemo/GRDBAsyncDemo/GRDBAsyncDemoApp.swift @@ -5,17 +5,12 @@ import SwiftUI struct GRDBAsyncDemoApp: App { var body: some Scene { WindowGroup { - AppView().environment(\.appDatabase, .shared) + AppView().appDatabase(.shared) } } } // MARK: - Give SwiftUI access to the database -// -// Define a new environment key that grants access to an AppDatabase. -// -// The technique is documented at -// . private struct AppDatabaseKey: EnvironmentKey { static var defaultValue: AppDatabase { .empty() } @@ -28,13 +23,10 @@ extension EnvironmentValues { } } -// In this demo app, views observe the database with the @Query property -// wrapper, defined in the GRDBQuery package. Its documentation recommends to -// define a dedicated initializer for `appDatabase` access, so we comply: - -extension Query where Request.DatabaseContext == AppDatabase { - /// Convenience initializer for requests that feed from `AppDatabase`. - init(_ request: Request) { - self.init(request, in: \.appDatabase) +extension View { + func appDatabase(_ appDatabase: AppDatabase) -> some View { + self + .environment(\.appDatabase, appDatabase) + .databaseContext(.readOnly { appDatabase.reader }) } } diff --git a/Documentation/DemoApps/GRDBAsyncDemo/GRDBAsyncDemo/PlayerRequest.swift b/Documentation/DemoApps/GRDBAsyncDemo/GRDBAsyncDemo/PlayerRequest.swift index 8c70aab8d..4d1d92460 100644 --- a/Documentation/DemoApps/GRDBAsyncDemo/GRDBAsyncDemo/PlayerRequest.swift +++ b/Documentation/DemoApps/GRDBAsyncDemo/GRDBAsyncDemo/PlayerRequest.swift @@ -1,4 +1,3 @@ -import Combine import GRDB import GRDBQuery @@ -14,37 +13,18 @@ import GRDBQuery /// List(players) { player in ... ) /// } /// } -struct PlayerRequest: Queryable { +struct PlayerRequest: ValueObservationQueryable { enum Ordering { case byScore case byName } + static var defaultValue: [Player] { [] } + /// The ordering used by the player request. var ordering: Ordering - // MARK: - Queryable Implementation - - static var defaultValue: [Player] { [] } - - func publisher(in appDatabase: AppDatabase) -> AnyPublisher<[Player], Error> { - // Build the publisher from the general-purpose read-only access - // granted by `appDatabase.reader`. - // Some apps will prefer to call a dedicated method of `appDatabase`. - ValueObservation - .tracking(fetchValue(_:)) - .publisher( - in: appDatabase.reader, - // The `.immediate` scheduling feeds the view right on - // subscription, and avoids an undesired animation when the - // application starts. - scheduling: .immediate) - .eraseToAnyPublisher() - } - - // This method is not required by Queryable, but it makes it easier - // to test PlayerRequest. - func fetchValue(_ db: Database) throws -> [Player] { + func fetch(_ db: Database) throws -> [Player] { switch ordering { case .byScore: return try Player.all().orderedByScore().fetchAll(db) diff --git a/Documentation/DemoApps/GRDBAsyncDemo/GRDBAsyncDemo/Views/AppView.swift b/Documentation/DemoApps/GRDBAsyncDemo/GRDBAsyncDemo/Views/AppView.swift index 1eda4c442..562b4aee8 100644 --- a/Documentation/DemoApps/GRDBAsyncDemo/GRDBAsyncDemo/Views/AppView.swift +++ b/Documentation/DemoApps/GRDBAsyncDemo/GRDBAsyncDemo/Views/AppView.swift @@ -43,7 +43,7 @@ struct AppView: View { stopEditing() })) .toolbar { toolbarContent } - .onChange(of: players) { players in + .onChange(of: players) { if players.isEmpty { stopEditing() } @@ -141,14 +141,14 @@ private struct ToggleOrderingButton: View { } } -struct AppView_Previews: PreviewProvider { - static var previews: some View { - Group { - // Preview the default, empty database - AppView() - - // Preview a database of random players - AppView().environment(\.appDatabase, .random()) - } - } +// MARK: - Previews + +#Preview("Empty") { + // Preview the default, empty database + AppView() +} + +#Preview("Populated") { + // Preview a database of random players + AppView().appDatabase(.random()) } diff --git a/Documentation/DemoApps/GRDBAsyncDemo/GRDBAsyncDemo/Views/PlayerCreationView.swift b/Documentation/DemoApps/GRDBAsyncDemo/GRDBAsyncDemo/Views/PlayerCreationView.swift index b71a3c2aa..a47fdd04d 100644 --- a/Documentation/DemoApps/GRDBAsyncDemo/GRDBAsyncDemo/Views/PlayerCreationView.swift +++ b/Documentation/DemoApps/GRDBAsyncDemo/GRDBAsyncDemo/Views/PlayerCreationView.swift @@ -43,8 +43,8 @@ struct PlayerCreationView: View { } } -struct PlayerCreationSheet_Previews: PreviewProvider { - static var previews: some View { - PlayerCreationView() - } +// MARK: - Previews + +#Preview { + PlayerCreationView() } diff --git a/Documentation/DemoApps/GRDBAsyncDemo/GRDBAsyncDemo/Views/PlayerEditionView.swift b/Documentation/DemoApps/GRDBAsyncDemo/GRDBAsyncDemo/Views/PlayerEditionView.swift index 79f524506..1ab97677d 100644 --- a/Documentation/DemoApps/GRDBAsyncDemo/GRDBAsyncDemo/Views/PlayerEditionView.swift +++ b/Documentation/DemoApps/GRDBAsyncDemo/GRDBAsyncDemo/Views/PlayerEditionView.swift @@ -15,7 +15,7 @@ struct PlayerEditionView: View { var body: some View { PlayerFormView(form: $form) - .onChange(of: isPresented) { isPresented in + .onChange(of: isPresented) { // Save when back button is pressed if !isPresented { Task { @@ -30,11 +30,11 @@ struct PlayerEditionView: View { } } -struct PlayerEditionView_Previews: PreviewProvider { - static var previews: some View { - NavigationView { - PlayerEditionView(player: Player.makeRandom()) - .navigationBarTitle("Player Edition") - } +// MARK: - Previews + +#Preview { + NavigationView { + PlayerEditionView(player: Player.makeRandom()) + .navigationBarTitle("Player Edition") } } diff --git a/Documentation/DemoApps/GRDBAsyncDemo/GRDBAsyncDemo/Views/PlayerFormView.swift b/Documentation/DemoApps/GRDBAsyncDemo/GRDBAsyncDemo/Views/PlayerFormView.swift index bc7883e28..590506d46 100644 --- a/Documentation/DemoApps/GRDBAsyncDemo/GRDBAsyncDemo/Views/PlayerFormView.swift +++ b/Documentation/DemoApps/GRDBAsyncDemo/GRDBAsyncDemo/Views/PlayerFormView.swift @@ -33,15 +33,16 @@ extension PlayerForm { } } -struct PlayerFormView_Previews: PreviewProvider { - static var previews: some View { - Group { - PlayerFormView(form: .constant(PlayerForm( - name: "", - score: ""))) - PlayerFormView(form: .constant(PlayerForm( - name: Player.randomName(), - score: "\(Player.randomScore())"))) - } - } +// MARK: - Previews + +#Preview("Empty") { + PlayerFormView(form: .constant(PlayerForm( + name: "", + score: ""))) +} + +#Preview("Prefilled") { + PlayerFormView(form: .constant(PlayerForm( + name: Player.randomName(), + score: "\(Player.randomScore())"))) } diff --git a/Documentation/DemoApps/GRDBAsyncDemo/GRDBAsyncDemo/Views/PlayerList.swift b/Documentation/DemoApps/GRDBAsyncDemo/GRDBAsyncDemo/Views/PlayerList.swift index b4ec9cee0..f156f786c 100644 --- a/Documentation/DemoApps/GRDBAsyncDemo/GRDBAsyncDemo/Views/PlayerList.swift +++ b/Documentation/DemoApps/GRDBAsyncDemo/GRDBAsyncDemo/Views/PlayerList.swift @@ -46,14 +46,14 @@ private struct PlayerRow: View { } } -struct PlayerList_Previews: PreviewProvider { - static var previews: some View { - NavigationView { - PlayerList(players: [ - Player(id: 1, name: "Arthur", score: 100), - Player(id: 2, name: "Barbara", score: 1000), - ]) - .navigationTitle("Preview") - } +// MARK: - Previews + +#Preview { + NavigationView { + PlayerList(players: [ + Player(id: 1, name: "Arthur", score: 100), + Player(id: 2, name: "Barbara", score: 1000), + ]) + .navigationTitle("Preview") } } diff --git a/Documentation/DemoApps/GRDBAsyncDemo/GRDBAsyncDemoTests/PlayerRequestTests.swift b/Documentation/DemoApps/GRDBAsyncDemo/GRDBAsyncDemoTests/PlayerRequestTests.swift index 2675f82d5..71d82ab40 100644 --- a/Documentation/DemoApps/GRDBAsyncDemo/GRDBAsyncDemoTests/PlayerRequestTests.swift +++ b/Documentation/DemoApps/GRDBAsyncDemo/GRDBAsyncDemoTests/PlayerRequestTests.swift @@ -16,7 +16,7 @@ class PlayerRequestTests: XCTestCase { // When we fetch players ordered by name let playerRequest = PlayerRequest(ordering: .byName) - let players = try dbQueue.read(playerRequest.fetchValue) + let players = try dbQueue.read(playerRequest.fetch) // Then the players are the two players ordered by name XCTAssertEqual(players, [player1, player2]) @@ -35,7 +35,7 @@ class PlayerRequestTests: XCTestCase { // When we fetch players ordered by score let playerRequest = PlayerRequest(ordering: .byScore) - let players = try dbQueue.read(playerRequest.fetchValue) + let players = try dbQueue.read(playerRequest.fetch) // Then the players are the two players ordered by score descending XCTAssertEqual(players, [player2, player1]) diff --git a/Documentation/DemoApps/GRDBCombineDemo/GRDBCombineDemo.xcodeproj/project.pbxproj b/Documentation/DemoApps/GRDBCombineDemo/GRDBCombineDemo.xcodeproj/project.pbxproj index 5435eaded..f1892a540 100644 --- a/Documentation/DemoApps/GRDBCombineDemo/GRDBCombineDemo.xcodeproj/project.pbxproj +++ b/Documentation/DemoApps/GRDBCombineDemo/GRDBCombineDemo.xcodeproj/project.pbxproj @@ -354,6 +354,7 @@ BUNDLE_LOADER = "$(TEST_HOST)"; CODE_SIGN_STYLE = Automatic; INFOPLIST_FILE = GRDBCombineDemoTests/Info.plist; + IPHONEOS_DEPLOYMENT_TARGET = 17.0; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/Frameworks", @@ -373,6 +374,7 @@ BUNDLE_LOADER = "$(TEST_HOST)"; CODE_SIGN_STYLE = Automatic; INFOPLIST_FILE = GRDBCombineDemoTests/Info.plist; + IPHONEOS_DEPLOYMENT_TARGET = 17.0; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/Frameworks", @@ -512,6 +514,7 @@ DEVELOPMENT_TEAM = ""; ENABLE_PREVIEWS = YES; INFOPLIST_FILE = GRDBCombineDemo/Info.plist; + IPHONEOS_DEPLOYMENT_TARGET = 17.0; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/Frameworks", @@ -533,6 +536,7 @@ DEVELOPMENT_TEAM = ""; ENABLE_PREVIEWS = YES; INFOPLIST_FILE = GRDBCombineDemo/Info.plist; + IPHONEOS_DEPLOYMENT_TARGET = 17.0; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/Frameworks", diff --git a/Documentation/DemoApps/GRDBCombineDemo/GRDBCombineDemo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/Documentation/DemoApps/GRDBCombineDemo/GRDBCombineDemo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index 5a507d565..216295601 100644 --- a/Documentation/DemoApps/GRDBCombineDemo/GRDBCombineDemo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/Documentation/DemoApps/GRDBCombineDemo/GRDBCombineDemo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -5,8 +5,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/groue/GRDBQuery", "state" : { - "revision" : "aefc0d7e7a64e841da33e1c8be7429da1bd9b5d6", - "version" : "0.6.0" + "revision" : "a6c46dd38ecf11a5c37732870dc03a384d582fba", + "version" : "0.9.0" } } ], diff --git a/Documentation/DemoApps/GRDBCombineDemo/GRDBCombineDemo/GRDBCombineDemoApp.swift b/Documentation/DemoApps/GRDBCombineDemo/GRDBCombineDemo/GRDBCombineDemoApp.swift index 3565a31cb..27db2c5ea 100644 --- a/Documentation/DemoApps/GRDBCombineDemo/GRDBCombineDemo/GRDBCombineDemoApp.swift +++ b/Documentation/DemoApps/GRDBCombineDemo/GRDBCombineDemo/GRDBCombineDemoApp.swift @@ -5,17 +5,12 @@ import SwiftUI struct GRDBCombineDemoApp: App { var body: some Scene { WindowGroup { - AppView().environment(\.appDatabase, .shared) + AppView().appDatabase(.shared) } } } // MARK: - Give SwiftUI access to the database -// -// Define a new environment key that grants access to an AppDatabase. -// -// The technique is documented at -// . private struct AppDatabaseKey: EnvironmentKey { static var defaultValue: AppDatabase { .empty() } @@ -28,13 +23,10 @@ extension EnvironmentValues { } } -// In this demo app, views observe the database with the @Query property -// wrapper, defined in the GRDBQuery package. Its documentation recommends to -// define a dedicated initializer for `appDatabase` access, so we comply: - -extension Query where Request.DatabaseContext == AppDatabase { - /// Convenience initializer for requests that feed from `AppDatabase`. - init(_ request: Request) { - self.init(request, in: \.appDatabase) +extension View { + func appDatabase(_ appDatabase: AppDatabase) -> some View { + self + .environment(\.appDatabase, appDatabase) + .databaseContext(.readOnly { appDatabase.reader }) } } diff --git a/Documentation/DemoApps/GRDBCombineDemo/GRDBCombineDemo/PlayerRequest.swift b/Documentation/DemoApps/GRDBCombineDemo/GRDBCombineDemo/PlayerRequest.swift index 8c70aab8d..4d1d92460 100644 --- a/Documentation/DemoApps/GRDBCombineDemo/GRDBCombineDemo/PlayerRequest.swift +++ b/Documentation/DemoApps/GRDBCombineDemo/GRDBCombineDemo/PlayerRequest.swift @@ -1,4 +1,3 @@ -import Combine import GRDB import GRDBQuery @@ -14,37 +13,18 @@ import GRDBQuery /// List(players) { player in ... ) /// } /// } -struct PlayerRequest: Queryable { +struct PlayerRequest: ValueObservationQueryable { enum Ordering { case byScore case byName } + static var defaultValue: [Player] { [] } + /// The ordering used by the player request. var ordering: Ordering - // MARK: - Queryable Implementation - - static var defaultValue: [Player] { [] } - - func publisher(in appDatabase: AppDatabase) -> AnyPublisher<[Player], Error> { - // Build the publisher from the general-purpose read-only access - // granted by `appDatabase.reader`. - // Some apps will prefer to call a dedicated method of `appDatabase`. - ValueObservation - .tracking(fetchValue(_:)) - .publisher( - in: appDatabase.reader, - // The `.immediate` scheduling feeds the view right on - // subscription, and avoids an undesired animation when the - // application starts. - scheduling: .immediate) - .eraseToAnyPublisher() - } - - // This method is not required by Queryable, but it makes it easier - // to test PlayerRequest. - func fetchValue(_ db: Database) throws -> [Player] { + func fetch(_ db: Database) throws -> [Player] { switch ordering { case .byScore: return try Player.all().orderedByScore().fetchAll(db) diff --git a/Documentation/DemoApps/GRDBCombineDemo/GRDBCombineDemo/Views/AppView.swift b/Documentation/DemoApps/GRDBCombineDemo/GRDBCombineDemo/Views/AppView.swift index 0879f3430..7c93e15cb 100644 --- a/Documentation/DemoApps/GRDBCombineDemo/GRDBCombineDemo/Views/AppView.swift +++ b/Documentation/DemoApps/GRDBCombineDemo/GRDBCombineDemo/Views/AppView.swift @@ -43,7 +43,7 @@ struct AppView: View { stopEditing() })) .toolbar { toolbarContent } - .onChange(of: players) { players in + .onChange(of: players) { if players.isEmpty { stopEditing() } @@ -132,14 +132,14 @@ private struct ToggleOrderingButton: View { } } -struct AppView_Previews: PreviewProvider { - static var previews: some View { - Group { - // Preview the default, empty database - AppView() - - // Preview a database of random players - AppView().environment(\.appDatabase, .random()) - } - } +// MARK: - Previews + +#Preview("Empty") { + // Preview the default, empty database + AppView() +} + +#Preview("Populated") { + // Preview a database of random players + AppView().appDatabase(.random()) } diff --git a/Documentation/DemoApps/GRDBCombineDemo/GRDBCombineDemo/Views/PlayerCreationView.swift b/Documentation/DemoApps/GRDBCombineDemo/GRDBCombineDemo/Views/PlayerCreationView.swift index 1c78289a9..f86876fd9 100644 --- a/Documentation/DemoApps/GRDBCombineDemo/GRDBCombineDemo/Views/PlayerCreationView.swift +++ b/Documentation/DemoApps/GRDBCombineDemo/GRDBCombineDemo/Views/PlayerCreationView.swift @@ -43,8 +43,8 @@ struct PlayerCreationView: View { } } -struct PlayerCreationSheet_Previews: PreviewProvider { - static var previews: some View { - PlayerCreationView() - } +// MARK: - Previews + +#Preview { + PlayerCreationView() } diff --git a/Documentation/DemoApps/GRDBCombineDemo/GRDBCombineDemo/Views/PlayerEditionView.swift b/Documentation/DemoApps/GRDBCombineDemo/GRDBCombineDemo/Views/PlayerEditionView.swift index a3bde6aa8..a3c559a1a 100644 --- a/Documentation/DemoApps/GRDBCombineDemo/GRDBCombineDemo/Views/PlayerEditionView.swift +++ b/Documentation/DemoApps/GRDBCombineDemo/GRDBCombineDemo/Views/PlayerEditionView.swift @@ -15,7 +15,7 @@ struct PlayerEditionView: View { var body: some View { PlayerFormView(form: $form) - .onChange(of: isPresented) { isPresented in + .onChange(of: isPresented) { // Save when back button is pressed if !isPresented { var savedPlayer = player @@ -28,11 +28,11 @@ struct PlayerEditionView: View { } } -struct PlayerEditionView_Previews: PreviewProvider { - static var previews: some View { - NavigationView { - PlayerEditionView(player: Player.makeRandom()) - .navigationBarTitle("Player Edition") - } +// MARK: - Previews + +#Preview { + NavigationView { + PlayerEditionView(player: Player.makeRandom()) + .navigationBarTitle("Player Edition") } } diff --git a/Documentation/DemoApps/GRDBCombineDemo/GRDBCombineDemo/Views/PlayerFormView.swift b/Documentation/DemoApps/GRDBCombineDemo/GRDBCombineDemo/Views/PlayerFormView.swift index bc7883e28..590506d46 100644 --- a/Documentation/DemoApps/GRDBCombineDemo/GRDBCombineDemo/Views/PlayerFormView.swift +++ b/Documentation/DemoApps/GRDBCombineDemo/GRDBCombineDemo/Views/PlayerFormView.swift @@ -33,15 +33,16 @@ extension PlayerForm { } } -struct PlayerFormView_Previews: PreviewProvider { - static var previews: some View { - Group { - PlayerFormView(form: .constant(PlayerForm( - name: "", - score: ""))) - PlayerFormView(form: .constant(PlayerForm( - name: Player.randomName(), - score: "\(Player.randomScore())"))) - } - } +// MARK: - Previews + +#Preview("Empty") { + PlayerFormView(form: .constant(PlayerForm( + name: "", + score: ""))) +} + +#Preview("Prefilled") { + PlayerFormView(form: .constant(PlayerForm( + name: Player.randomName(), + score: "\(Player.randomScore())"))) } diff --git a/Documentation/DemoApps/GRDBCombineDemo/GRDBCombineDemo/Views/PlayerList.swift b/Documentation/DemoApps/GRDBCombineDemo/GRDBCombineDemo/Views/PlayerList.swift index 1b41a8bc4..7913c73c6 100644 --- a/Documentation/DemoApps/GRDBCombineDemo/GRDBCombineDemo/Views/PlayerList.swift +++ b/Documentation/DemoApps/GRDBCombineDemo/GRDBCombineDemo/Views/PlayerList.swift @@ -44,14 +44,14 @@ private struct PlayerRow: View { } } -struct PlayerList_Previews: PreviewProvider { - static var previews: some View { - NavigationView { - PlayerList(players: [ - Player(id: 1, name: "Arthur", score: 100), - Player(id: 2, name: "Barbara", score: 1000), - ]) - .navigationTitle("Preview") - } +// MARK: - Previews + +#Preview { + NavigationView { + PlayerList(players: [ + Player(id: 1, name: "Arthur", score: 100), + Player(id: 2, name: "Barbara", score: 1000), + ]) + .navigationTitle("Preview") } } diff --git a/Documentation/DemoApps/GRDBCombineDemo/GRDBCombineDemoTests/PlayerRequestTests.swift b/Documentation/DemoApps/GRDBCombineDemo/GRDBCombineDemoTests/PlayerRequestTests.swift index 151d8e41e..c9e58da1e 100644 --- a/Documentation/DemoApps/GRDBCombineDemo/GRDBCombineDemoTests/PlayerRequestTests.swift +++ b/Documentation/DemoApps/GRDBCombineDemo/GRDBCombineDemoTests/PlayerRequestTests.swift @@ -16,7 +16,7 @@ class PlayerRequestTests: XCTestCase { // When we fetch players ordered by name let playerRequest = PlayerRequest(ordering: .byName) - let players = try dbQueue.read(playerRequest.fetchValue) + let players = try dbQueue.read(playerRequest.fetch) // Then the players are the two players ordered by name XCTAssertEqual(players, [player1, player2]) @@ -35,7 +35,7 @@ class PlayerRequestTests: XCTestCase { // When we fetch players ordered by score let playerRequest = PlayerRequest(ordering: .byScore) - let players = try dbQueue.read(playerRequest.fetchValue) + let players = try dbQueue.read(playerRequest.fetch) // Then the players are the two players ordered by score descending XCTAssertEqual(players, [player2, player1]) diff --git a/Documentation/DemoApps/GRDBDemoiOS/GRDBDemoiOS.xcodeproj/project.pbxproj b/Documentation/DemoApps/GRDBDemoiOS/GRDBDemoiOS.xcodeproj/project.pbxproj index 4d38142d0..827e5c560 100644 --- a/Documentation/DemoApps/GRDBDemoiOS/GRDBDemoiOS.xcodeproj/project.pbxproj +++ b/Documentation/DemoApps/GRDBDemoiOS/GRDBDemoiOS.xcodeproj/project.pbxproj @@ -588,6 +588,7 @@ DEVELOPMENT_TEAM = AMD8W895CT; GCC_C_LANGUAGE_STANDARD = gnu11; INFOPLIST_FILE = GRDBDemoiOSTests/Info.plist; + IPHONEOS_DEPLOYMENT_TARGET = 17.0; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/Frameworks", @@ -614,6 +615,7 @@ DEVELOPMENT_TEAM = AMD8W895CT; GCC_C_LANGUAGE_STANDARD = gnu11; INFOPLIST_FILE = GRDBDemoiOSTests/Info.plist; + IPHONEOS_DEPLOYMENT_TARGET = 17.0; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/Frameworks", @@ -828,6 +830,7 @@ CLANG_ENABLE_OBJC_WEAK = YES; DEVELOPMENT_TEAM = AMD8W895CT; INFOPLIST_FILE = GRDBDemoiOS/Info.plist; + IPHONEOS_DEPLOYMENT_TARGET = 17.0; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/Frameworks", @@ -845,6 +848,7 @@ CLANG_ENABLE_OBJC_WEAK = YES; DEVELOPMENT_TEAM = AMD8W895CT; INFOPLIST_FILE = GRDBDemoiOS/Info.plist; + IPHONEOS_DEPLOYMENT_TARGET = 17.0; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/Frameworks",