From 6887441264a17ea15db0e89bbd34fcb1498c18e7 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Wed, 7 Apr 2021 15:32:59 +0200 Subject: [PATCH 1/7] Ensure Query can be updated --- .../DemoApps/GRDBCombineDemo/GRDBCombineDemo/Query.swift | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Documentation/DemoApps/GRDBCombineDemo/GRDBCombineDemo/Query.swift b/Documentation/DemoApps/GRDBCombineDemo/GRDBCombineDemo/Query.swift index 083227e00..23e5e829e 100644 --- a/Documentation/DemoApps/GRDBCombineDemo/GRDBCombineDemo/Query.swift +++ b/Documentation/DemoApps/GRDBCombineDemo/GRDBCombineDemo/Query.swift @@ -40,7 +40,10 @@ struct Query: DynamicProperty { var projectedValue: Binding { Binding( get: { core.query ?? baseQuery }, - set: { core.query = $0 }) + set: { + core.usesBaseQuery = false + core.query = $0 + }) } init(_ query: Query) { @@ -52,13 +55,14 @@ struct Query: DynamicProperty { fatalError("Attempting to use @Query without any database in the environment") } // Feed core with necessary information, and make sure tracking has started - if core.query == nil { core.query = baseQuery } + if core.usesBaseQuery { core.query = baseQuery } core.startTrackingIfNecessary(in: databaseReader) } private class Core: ObservableObject { private(set) var value: Query.Value? var databaseReader: DatabaseReader? + var usesBaseQuery = true var query: Query? { willSet { if query != newValue { From 481f6e93e58a2349d956f3e92d699e14dcb70448 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Thu, 8 Apr 2021 10:41:20 +0200 Subject: [PATCH 2/7] Add UI test to show late-changing of Query --- .../GRDBCombineDemo.xcodeproj/project.pbxproj | 123 +++++++++++++++++- .../xcschemes/GRDBCombineDemo.xcscheme | 10 ++ .../GRDBCombineDemo/AppDatabase.swift | 19 +++ .../GRDBCombineDemo/GRDBCombineDemoApp.swift | 8 +- .../GRDBCombineDemo/Persistence.swift | 13 +- .../GRDBCombineDemo/Views/AppView.swift | 12 +- .../Views/PlayerFormView.swift | 2 + .../GRDBCombineDemoUITests.swift | 66 ++++++++++ .../GRDBCombineDemoUITests/Info.plist | 22 ++++ 9 files changed, 268 insertions(+), 7 deletions(-) create mode 100644 Documentation/DemoApps/GRDBCombineDemo/GRDBCombineDemoUITests/GRDBCombineDemoUITests.swift create mode 100644 Documentation/DemoApps/GRDBCombineDemo/GRDBCombineDemoUITests/Info.plist diff --git a/Documentation/DemoApps/GRDBCombineDemo/GRDBCombineDemo.xcodeproj/project.pbxproj b/Documentation/DemoApps/GRDBCombineDemo/GRDBCombineDemo.xcodeproj/project.pbxproj index cca13534b..fb0f73aa7 100644 --- a/Documentation/DemoApps/GRDBCombineDemo/GRDBCombineDemo.xcodeproj/project.pbxproj +++ b/Documentation/DemoApps/GRDBCombineDemo/GRDBCombineDemo.xcodeproj/project.pbxproj @@ -27,6 +27,7 @@ 567C3E792520BB650011F6E9 /* Localizable.stringsdict in Resources */ = {isa = PBXBuildFile; fileRef = 567C3E752520BB650011F6E9 /* Localizable.stringsdict */; }; 567C3E7A2520BB650011F6E9 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 567C3E772520BB650011F6E9 /* LaunchScreen.storyboard */; }; 56B6D1092619EC1B003CC455 /* PlayerRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56B6D1082619EC1B003CC455 /* PlayerRequest.swift */; }; + 78E2F9E6261EEC22005D1F7F /* GRDBCombineDemoUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78E2F9E5261EEC22005D1F7F /* GRDBCombineDemoUITests.swift */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -100,6 +101,13 @@ remoteGlobalIDString = 56E5D7C91B4D3FED00430942; remoteInfo = GRDBiOS; }; + 78E2F9E8261EEC22005D1F7F /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 567C3E0E2520B6DE0011F6E9 /* Project object */; + proxyType = 1; + remoteGlobalIDString = 567C3E152520B6DE0011F6E9; + remoteInfo = GRDBCombineDemo; + }; /* End PBXContainerItemProxy section */ /* Begin PBXCopyFilesBuildPhase section */ @@ -140,6 +148,9 @@ 567C3E762520BB650011F6E9 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.stringsdict; name = en; path = en.lproj/Localizable.stringsdict; sourceTree = ""; }; 567C3E782520BB650011F6E9 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 56B6D1082619EC1B003CC455 /* PlayerRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlayerRequest.swift; sourceTree = ""; }; + 78E2F9E3261EEC22005D1F7F /* GRDBCombineDemoUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = GRDBCombineDemoUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; + 78E2F9E5261EEC22005D1F7F /* GRDBCombineDemoUITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GRDBCombineDemoUITests.swift; sourceTree = ""; }; + 78E2F9E7261EEC22005D1F7F /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -158,6 +169,13 @@ ); runOnlyForDeploymentPostprocessing = 0; }; + 78E2F9E0261EEC22005D1F7F /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ @@ -196,6 +214,7 @@ 567C3E292520B7000011F6E9 /* GRDB.xcodeproj */, 567C3E182520B6DE0011F6E9 /* GRDBCombineDemo */, 56026C9925B8A7D000D1DF3F /* GRDBCombineDemoTests */, + 78E2F9E4261EEC22005D1F7F /* GRDBCombineDemoUITests */, 567C3E172520B6DE0011F6E9 /* Products */, 567C3E4D2520B70E0011F6E9 /* Frameworks */, ); @@ -206,6 +225,7 @@ children = ( 567C3E162520B6DE0011F6E9 /* GRDBCombineDemo.app */, 56026C9825B8A7D000D1DF3F /* GRDBCombineDemoTests.xctest */, + 78E2F9E3261EEC22005D1F7F /* GRDBCombineDemoUITests.xctest */, ); name = Products; sourceTree = ""; @@ -269,6 +289,15 @@ path = Views; sourceTree = ""; }; + 78E2F9E4261EEC22005D1F7F /* GRDBCombineDemoUITests */ = { + isa = PBXGroup; + children = ( + 78E2F9E5261EEC22005D1F7F /* GRDBCombineDemoUITests.swift */, + 78E2F9E7261EEC22005D1F7F /* Info.plist */, + ); + path = GRDBCombineDemoUITests; + sourceTree = ""; + }; /* End PBXGroup section */ /* Begin PBXNativeTarget section */ @@ -309,13 +338,31 @@ productReference = 567C3E162520B6DE0011F6E9 /* GRDBCombineDemo.app */; productType = "com.apple.product-type.application"; }; + 78E2F9E2261EEC22005D1F7F /* GRDBCombineDemoUITests */ = { + isa = PBXNativeTarget; + buildConfigurationList = 78E2F9F3261EEC22005D1F7F /* Build configuration list for PBXNativeTarget "GRDBCombineDemoUITests" */; + buildPhases = ( + 78E2F9DF261EEC22005D1F7F /* Sources */, + 78E2F9E0261EEC22005D1F7F /* Frameworks */, + 78E2F9E1261EEC22005D1F7F /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + 78E2F9E9261EEC22005D1F7F /* PBXTargetDependency */, + ); + name = GRDBCombineDemoUITests; + productName = GRDBCombineDemoUITests; + productReference = 78E2F9E3261EEC22005D1F7F /* GRDBCombineDemoUITests.xctest */; + productType = "com.apple.product-type.bundle.ui-testing"; + }; /* End PBXNativeTarget section */ /* Begin PBXProject section */ 567C3E0E2520B6DE0011F6E9 /* Project object */ = { isa = PBXProject; attributes = { - LastSwiftUpdateCheck = 1230; + LastSwiftUpdateCheck = 1250; LastUpgradeCheck = 1200; TargetAttributes = { 56026C9725B8A7D000D1DF3F = { @@ -325,6 +372,10 @@ 567C3E152520B6DE0011F6E9 = { CreatedOnToolsVersion = 12.0; }; + 78E2F9E2261EEC22005D1F7F = { + CreatedOnToolsVersion = 12.5; + TestTargetID = 567C3E152520B6DE0011F6E9; + }; }; }; buildConfigurationList = 567C3E112520B6DE0011F6E9 /* Build configuration list for PBXProject "GRDBCombineDemo" */; @@ -348,6 +399,7 @@ targets = ( 567C3E152520B6DE0011F6E9 /* GRDBCombineDemo */, 56026C9725B8A7D000D1DF3F /* GRDBCombineDemoTests */, + 78E2F9E2261EEC22005D1F7F /* GRDBCombineDemoUITests */, ); }; /* End PBXProject section */ @@ -430,6 +482,13 @@ ); runOnlyForDeploymentPostprocessing = 0; }; + 78E2F9E1261EEC22005D1F7F /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; /* End PBXResourcesBuildPhase section */ /* Begin PBXSourcesBuildPhase section */ @@ -461,6 +520,14 @@ ); runOnlyForDeploymentPostprocessing = 0; }; + 78E2F9DF261EEC22005D1F7F /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 78E2F9E6261EEC22005D1F7F /* GRDBCombineDemoUITests.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; /* End PBXSourcesBuildPhase section */ /* Begin PBXTargetDependency section */ @@ -474,6 +541,11 @@ name = GRDBiOS; targetProxy = 567C3E512520B71C0011F6E9 /* PBXContainerItemProxy */; }; + 78E2F9E9261EEC22005D1F7F /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = 567C3E152520B6DE0011F6E9 /* GRDBCombineDemo */; + targetProxy = 78E2F9E8261EEC22005D1F7F /* PBXContainerItemProxy */; + }; /* End PBXTargetDependency section */ /* Begin PBXVariantGroup section */ @@ -696,6 +768,46 @@ }; name = Release; }; + 78E2F9EA261EEC22005D1F7F /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + CODE_SIGN_STYLE = Automatic; + DEVELOPMENT_TEAM = Y5PE65HELJ; + INFOPLIST_FILE = GRDBCombineDemoUITests/Info.plist; + IPHONEOS_DEPLOYMENT_TARGET = 14.5; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + "@loader_path/Frameworks", + ); + PRODUCT_BUNDLE_IDENTIFIER = com.groue.GRDBCombineDemoUITests; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + TEST_TARGET_NAME = GRDBCombineDemo; + }; + name = Debug; + }; + 78E2F9EB261EEC22005D1F7F /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + CODE_SIGN_STYLE = Automatic; + DEVELOPMENT_TEAM = Y5PE65HELJ; + INFOPLIST_FILE = GRDBCombineDemoUITests/Info.plist; + IPHONEOS_DEPLOYMENT_TARGET = 14.5; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + "@loader_path/Frameworks", + ); + PRODUCT_BUNDLE_IDENTIFIER = com.groue.GRDBCombineDemoUITests; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + TEST_TARGET_NAME = GRDBCombineDemo; + }; + name = Release; + }; /* End XCBuildConfiguration section */ /* Begin XCConfigurationList section */ @@ -726,6 +838,15 @@ defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; }; + 78E2F9F3261EEC22005D1F7F /* Build configuration list for PBXNativeTarget "GRDBCombineDemoUITests" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 78E2F9EA261EEC22005D1F7F /* Debug */, + 78E2F9EB261EEC22005D1F7F /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; /* End XCConfigurationList section */ }; rootObject = 567C3E0E2520B6DE0011F6E9 /* Project object */; diff --git a/Documentation/DemoApps/GRDBCombineDemo/GRDBCombineDemo.xcodeproj/xcshareddata/xcschemes/GRDBCombineDemo.xcscheme b/Documentation/DemoApps/GRDBCombineDemo/GRDBCombineDemo.xcodeproj/xcshareddata/xcschemes/GRDBCombineDemo.xcscheme index 3b324622e..5a7922e7c 100644 --- a/Documentation/DemoApps/GRDBCombineDemo/GRDBCombineDemo.xcodeproj/xcshareddata/xcschemes/GRDBCombineDemo.xcscheme +++ b/Documentation/DemoApps/GRDBCombineDemo/GRDBCombineDemo.xcodeproj/xcshareddata/xcschemes/GRDBCombineDemo.xcscheme @@ -38,6 +38,16 @@ ReferencedContainer = "container:GRDBCombineDemo.xcodeproj"> + + + + XCUIApplication { + // UI tests must launch the application that they test. + let app = XCUIApplication() + // We enforce a fresh database to ensure 8 random players. + app.launchArguments = ["-reset", "-fixedTestData"] + app.launch() + return app + } + + func testInitialSortingIsByScore() throws { + let app = runApp() + + let getFirstCell = { () -> XCUIElement in + app.tables.element(boundBy: 0).cells.element(boundBy: 0) + } + + // Given default sorting, Henriette must be on top + XCTAssertEqual(getFirstCell().label, "Craig, 8 points") + + // Reverse sorting will bring Arthur on top (sort by name) + app.buttons["Score"].tap() + XCTAssertEqual(getFirstCell().label, "Arthur, 5 points") + } + + func testListAndAddPlayer() throws { + let app = runApp() + + // Ensure we have 8 players visible + XCTAssert(app.tables.cells.count == 8) + + // add a player + app.buttons["New Player"].tap() + + let playerNameField = app.textFields["Player Name"] + playerNameField.tap() + playerNameField.typeText("Tim Apple") + + app.buttons["Save"].tap() + + // This is suboptimal, but we need to wait for the animation to finish + // A better way could be to disable animations globally, + // and/or a hook to detect when the async fetch completes. + sleep(2) + + XCTAssert(app.tables.cells.count == 9) + } +} diff --git a/Documentation/DemoApps/GRDBCombineDemo/GRDBCombineDemoUITests/Info.plist b/Documentation/DemoApps/GRDBCombineDemo/GRDBCombineDemoUITests/Info.plist new file mode 100644 index 000000000..64d65ca49 --- /dev/null +++ b/Documentation/DemoApps/GRDBCombineDemo/GRDBCombineDemoUITests/Info.plist @@ -0,0 +1,22 @@ + + + + + CFBundleDevelopmentRegion + $(DEVELOPMENT_LANGUAGE) + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + $(PRODUCT_BUNDLE_PACKAGE_TYPE) + CFBundleShortVersionString + 1.0 + CFBundleVersion + 1 + + From d4f11029762b8114f6a0705b150146671cf44380 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Sat, 10 Apr 2021 15:07:02 +0200 Subject: [PATCH 3/7] Document how AppDatabase.makeShared() supports test This helps readers understand the purpose of those lines, and remove them if they are not interested. --- .../GRDBCombineDemo/Persistence.swift | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/Documentation/DemoApps/GRDBCombineDemo/GRDBCombineDemo/Persistence.swift b/Documentation/DemoApps/GRDBCombineDemo/GRDBCombineDemo/Persistence.swift index 7fbd75676..ed3b01e39 100644 --- a/Documentation/DemoApps/GRDBCombineDemo/GRDBCombineDemo/Persistence.swift +++ b/Documentation/DemoApps/GRDBCombineDemo/GRDBCombineDemo/Persistence.swift @@ -6,35 +6,39 @@ extension AppDatabase { private static func makeShared() -> AppDatabase { do { - // Create a folder for storing the SQLite database, as well as + // Pick a folder for storing the SQLite database, as well as // the various temporary files created during normal database // operations (https://sqlite.org/tempfiles.html). let fileManager = FileManager() let folderURL = try fileManager .url(for: .applicationSupportDirectory, in: .userDomainMask, appropriateFor: nil, create: true) .appendingPathComponent("database", isDirectory: true) + + // Support for tests: delete the database if requested + if CommandLine.arguments.contains("-reset") { + try? fileManager.removeItem(at: folderURL) + } + + // Create the database folder if needed try fileManager.createDirectory(at: folderURL, withIntermediateDirectories: true) // Connect to a database on disk // See https://github.com/groue/GRDB.swift/blob/master/README.md#database-connections let dbURL = folderURL.appendingPathComponent("db.sqlite") - - if CommandLine.arguments.contains("-reset") { - try? fileManager.removeItem(at: dbURL) - } - let dbPool = try DatabasePool(path: dbURL.path) // Create the AppDatabase let appDatabase = try AppDatabase(dbPool) - // Populate the database if it is empty, for better demo purpose. + // Prepare the database with test fixtures if requested if CommandLine.arguments.contains("-fixedTestData") { try appDatabase.createPlayersForUITests() } else { + // Otherwise, populate the database if it is empty, for better + // demo purpose. try appDatabase.createRandomPlayersIfEmpty() } - + return appDatabase } catch { // Replace this implementation with code to handle the error appropriately. From 0f70e9d9c95e304ddd187fc1298b21e87c0e80b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Sat, 10 Apr 2021 15:35:42 +0200 Subject: [PATCH 4/7] Remove all DEVELOPMENT_TEAM from demo app --- .../GRDBCombineDemo.xcodeproj/project.pbxproj | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Documentation/DemoApps/GRDBCombineDemo/GRDBCombineDemo.xcodeproj/project.pbxproj b/Documentation/DemoApps/GRDBCombineDemo/GRDBCombineDemo.xcodeproj/project.pbxproj index fb0f73aa7..ed64b3788 100644 --- a/Documentation/DemoApps/GRDBCombineDemo/GRDBCombineDemo.xcodeproj/project.pbxproj +++ b/Documentation/DemoApps/GRDBCombineDemo/GRDBCombineDemo.xcodeproj/project.pbxproj @@ -731,7 +731,7 @@ ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; CODE_SIGN_STYLE = Automatic; DEVELOPMENT_ASSET_PATHS = "\"GRDBCombineDemo/Preview Content\""; - DEVELOPMENT_TEAM = AMD8W895CT; + DEVELOPMENT_TEAM = ""; ENABLE_PREVIEWS = YES; INFOPLIST_FILE = GRDBCombineDemo/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 14.0; @@ -753,7 +753,7 @@ ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; CODE_SIGN_STYLE = Automatic; DEVELOPMENT_ASSET_PATHS = "\"GRDBCombineDemo/Preview Content\""; - DEVELOPMENT_TEAM = AMD8W895CT; + DEVELOPMENT_TEAM = ""; ENABLE_PREVIEWS = YES; INFOPLIST_FILE = GRDBCombineDemo/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 14.0; @@ -772,7 +772,7 @@ isa = XCBuildConfiguration; buildSettings = { CODE_SIGN_STYLE = Automatic; - DEVELOPMENT_TEAM = Y5PE65HELJ; + DEVELOPMENT_TEAM = ""; INFOPLIST_FILE = GRDBCombineDemoUITests/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 14.5; LD_RUNPATH_SEARCH_PATHS = ( @@ -792,7 +792,7 @@ isa = XCBuildConfiguration; buildSettings = { CODE_SIGN_STYLE = Automatic; - DEVELOPMENT_TEAM = Y5PE65HELJ; + DEVELOPMENT_TEAM = ""; INFOPLIST_FILE = GRDBCombineDemoUITests/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 14.5; LD_RUNPATH_SEARCH_PATHS = ( From fd61a5f1eadea775945c144e17d66b0ca39381d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Sat, 10 Apr 2021 15:37:18 +0200 Subject: [PATCH 5/7] Remove 14.5 IPHONEOS_DEPLOYMENT_TARGET Tests succeed on 14.4, and 14.0 target does not generate any Xcode warning --- .../GRDBCombineDemo/GRDBCombineDemo.xcodeproj/project.pbxproj | 2 -- 1 file changed, 2 deletions(-) diff --git a/Documentation/DemoApps/GRDBCombineDemo/GRDBCombineDemo.xcodeproj/project.pbxproj b/Documentation/DemoApps/GRDBCombineDemo/GRDBCombineDemo.xcodeproj/project.pbxproj index ed64b3788..854b7a323 100644 --- a/Documentation/DemoApps/GRDBCombineDemo/GRDBCombineDemo.xcodeproj/project.pbxproj +++ b/Documentation/DemoApps/GRDBCombineDemo/GRDBCombineDemo.xcodeproj/project.pbxproj @@ -774,7 +774,6 @@ CODE_SIGN_STYLE = Automatic; DEVELOPMENT_TEAM = ""; INFOPLIST_FILE = GRDBCombineDemoUITests/Info.plist; - IPHONEOS_DEPLOYMENT_TARGET = 14.5; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/Frameworks", @@ -794,7 +793,6 @@ CODE_SIGN_STYLE = Automatic; DEVELOPMENT_TEAM = ""; INFOPLIST_FILE = GRDBCombineDemoUITests/Info.plist; - IPHONEOS_DEPLOYMENT_TARGET = 14.5; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/Frameworks", From a5ffc52dbec8c6277ef1de70c0e1e7903f4c339a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Sat, 10 Apr 2021 15:45:00 +0200 Subject: [PATCH 6/7] Restore the barebone app setup Leave the AppView(initialOrdering:) initializer, though, so that readers can get some inspiration. --- .../GRDBCombineDemo/GRDBCombineDemoApp.swift | 8 +------- .../GRDBCombineDemo/Views/AppView.swift | 17 ++++++++++------- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/Documentation/DemoApps/GRDBCombineDemo/GRDBCombineDemo/GRDBCombineDemoApp.swift b/Documentation/DemoApps/GRDBCombineDemo/GRDBCombineDemo/GRDBCombineDemoApp.swift index 5b31958b7..aef733ade 100644 --- a/Documentation/DemoApps/GRDBCombineDemo/GRDBCombineDemo/GRDBCombineDemoApp.swift +++ b/Documentation/DemoApps/GRDBCombineDemo/GRDBCombineDemo/GRDBCombineDemoApp.swift @@ -3,15 +3,9 @@ import SwiftUI @main struct GRDBCombineDemoApp: App { - @State var initialOrdering: PlayerRequest.Ordering = .byName - var body: some Scene { WindowGroup { - AppView(initialOrdering: initialOrdering) - .environment(\.appDatabase, AppDatabase.shared) - .onAppear { - initialOrdering = .byScore - } + AppView().environment(\.appDatabase, AppDatabase.shared) } } } diff --git a/Documentation/DemoApps/GRDBCombineDemo/GRDBCombineDemo/Views/AppView.swift b/Documentation/DemoApps/GRDBCombineDemo/GRDBCombineDemo/Views/AppView.swift index 583e17bc9..c414e001e 100644 --- a/Documentation/DemoApps/GRDBCombineDemo/GRDBCombineDemo/Views/AppView.swift +++ b/Documentation/DemoApps/GRDBCombineDemo/GRDBCombineDemo/Views/AppView.swift @@ -6,15 +6,18 @@ struct AppView: View { @Environment(\.appDatabase) private var appDatabase /// The `players` property is kept up-to-date with the list of players. - @Query(PlayerRequest(ordering: .byName)) private var players: [Player] + @Query(PlayerRequest(ordering: .byScore)) private var players: [Player] /// Tracks the presentation of the player creation sheet. @State private var newPlayerIsPresented = false - init(initialOrdering: PlayerRequest.Ordering) { - // Example to update a query on init - _players = Query(PlayerRequest(ordering: initialOrdering)) - } + // If you want to define the query on initialization, you will prefer: + // + // @Query private var players: [Player] + // + // init(initialOrdering: PlayerRequest.Ordering) { + // _players = Query(PlayerRequest(ordering: initialOrdering)) + // } var body: some View { NavigationView { @@ -89,10 +92,10 @@ struct AppView_Previews: PreviewProvider { static var previews: some View { Group { // Preview a database of random players - AppView(initialOrdering: .byScore).environment(\.appDatabase, .random()) + AppView().environment(\.appDatabase, .random()) // Preview an empty database - AppView(initialOrdering: .byScore).environment(\.appDatabase, .empty()) + AppView().environment(\.appDatabase, .empty()) } } } From c34615ced323aa5802a7b61afdb997b93f71e1a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Sat, 10 Apr 2021 16:10:02 +0200 Subject: [PATCH 7/7] Document that @steipete's test has turned moot We don't 100% need to address this now, but we 100% need to remember this in the future. --- .../GRDBCombineDemoUITests.swift | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/Documentation/DemoApps/GRDBCombineDemo/GRDBCombineDemoUITests/GRDBCombineDemoUITests.swift b/Documentation/DemoApps/GRDBCombineDemo/GRDBCombineDemoUITests/GRDBCombineDemoUITests.swift index 9e774d925..0a6f29dd8 100644 --- a/Documentation/DemoApps/GRDBCombineDemo/GRDBCombineDemoUITests/GRDBCombineDemoUITests.swift +++ b/Documentation/DemoApps/GRDBCombineDemo/GRDBCombineDemoUITests/GRDBCombineDemoUITests.swift @@ -26,6 +26,21 @@ class GRDBCombineDemoUITests: XCTestCase { return app } + // This test, introduced in 481f6e93, tests the @Query fix added in + // 68874412. The fix expresses itself when a view defines an @Query + // property that is replaced in the view initializer, as in 481f6e93. + // + // It happens that I did not find that this particular view setup was suited + // for a demo app. The demo has to find a delicate balance, not too trivial, + // but without gratuitous complexity. + // + // I simplified the demo app in a5ffc52d, and we no longer have any view + // that defines an @Query property which is replaced in the view + // initializer. This means that this test no longer checks against + // 68874412 regressions! + // + // Whenever the @Query property wrapper ships with GRDB itself, make sure + // we test for those regressions! func testInitialSortingIsByScore() throws { let app = runApp()