Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
205 changes: 171 additions & 34 deletions Examples/Examples.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
BuildableIdentifier = "primary"
BlueprintIdentifier = "CA2BDD9C2E71C30B000974D3"
BuildableName = "CloudKitDemo.app"
BlueprintName = "CloudKitDemo"
ReferencedContainer = "container:Examples.xcodeproj">
</BuildableReference>
</BuildActionEntry>
Expand Down Expand Up @@ -46,6 +47,7 @@
BuildableIdentifier = "primary"
BlueprintIdentifier = "CA2BDD9C2E71C30B000974D3"
BuildableName = "CloudKitDemo.app"
BlueprintName = "CloudKitDemo"
ReferencedContainer = "container:Examples.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
Expand All @@ -62,6 +64,7 @@
BuildableIdentifier = "primary"
BlueprintIdentifier = "CA2BDD9C2E71C30B000974D3"
BuildableName = "CloudKitDemo.app"
BlueprintName = "CloudKitDemo"
ReferencedContainer = "container:Examples.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "2700"
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES"
buildArchitectures = "Automatic">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "DC1584A530363595009DD95C"
BuildableName = "Integration.app"
ReferencedContainer = "container:Examples.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
shouldAutocreateTestPlan = "YES">
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES"
queueDebuggingEnabled = "No">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "DC1584A530363595009DD95C"
BuildableName = "Integration.app"
ReferencedContainer = "container:Examples.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "DC1584A530363595009DD95C"
BuildableName = "Integration.app"
ReferencedContainer = "container:Examples.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"colors" : [
{
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"images" : [
{
"idiom" : "universal",
"platform" : "ios",
"size" : "1024x1024"
},
{
"appearances" : [
{
"appearance" : "luminosity",
"value" : "dark"
}
],
"idiom" : "universal",
"platform" : "ios",
"size" : "1024x1024"
},
{
"appearances" : [
{
"appearance" : "luminosity",
"value" : "tinted"
}
],
"idiom" : "universal",
"platform" : "ios",
"size" : "1024x1024"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
6 changes: 6 additions & 0 deletions Examples/Integration/Assets.xcassets/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
9 changes: 9 additions & 0 deletions Examples/Integration/IntegrationApp.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import SwiftUI

@main
struct IntegrationApp: App {
var body: some Scene {
WindowGroup {
}
}
}
105 changes: 105 additions & 0 deletions Examples/Integration/Regression Coverage/ChildIdentityReset.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
import SQLiteData
import SwiftUI

struct ChildIdentityResetCaseStudy: SwiftUICaseStudy {
let readMe = """
This demonstrates that the `@Fetch*` tools behave like `@State` when a view's identity \
changes: their state survives re-renders of the parent view, but is discarded and rebuilt \
when the parent changes the child view's identity with the `id` view modifier.

Toggle "Favorites only" in the child view to load a filtered query, then tap "Reset child \
identity". The child view is rebuilt from scratch: the toggle returns to its default and \
the list returns to the unfiltered query, keeping the UI and data consistent.
"""
let caseStudyTitle = "Resetting child identity"

@State private var resetCount = 0

var body: some View {
List {
Section {
Button("Reset child identity: \(resetCount)") {
resetCount += 1
}
}
FactsListView()
.id(resetCount)
}
}
}

private struct FactsListView: View {
@State private var isFavoritesOnly = false
@FetchAll(Fact.all) private var facts

var body: some View {
Section {
Toggle("Favorites only", isOn: $isFavoritesOnly)
ForEach(facts) { fact in
HStack {
Text(fact.body)
Spacer()
if fact.isFavorite {
Image(systemName: "star.fill")
.foregroundStyle(.yellow)
}
}
}
}
.task(id: isFavoritesOnly) {
await withErrorReporting {
if isFavoritesOnly {
try await $facts.load(Fact.where(\.isFavorite)).task
} else {
try await $facts.load(Fact.all).task
}
}
}
}
}

@Table
nonisolated private struct Fact: Identifiable {
let id: Int
var body: String
var isFavorite = false
}

extension DatabaseWriter where Self == DatabaseQueue {
static var childIdentityResetDatabase: Self {
let databaseQueue = try! DatabaseQueue()
var migrator = DatabaseMigrator()
migrator.registerMigration("Create 'facts' table") { db in
try #sql(
"""
CREATE TABLE "facts" (
"id" INTEGER PRIMARY KEY AUTOINCREMENT,
"body" TEXT NOT NULL,
"isFavorite" INTEGER NOT NULL DEFAULT 0
) STRICT
"""
)
.execute(db)
try Fact.insert {
Fact.Draft(body: "SQLite was first released in the year 2000.", isFavorite: true)
Fact.Draft(body: "SQLite is the most widely deployed database in the world.")
Fact.Draft(body: "SQLite is a C library, not a client-server database.", isFavorite: true)
Fact.Draft(body: "SQLite databases are a single file on disk.")
}
.execute(db)
}
try! migrator.migrate(databaseQueue)
return databaseQueue
}
}

#Preview {
let _ = prepareDependencies {
$0.defaultDatabase = .childIdentityResetDatabase
}
NavigationStack {
CaseStudyView {
ChildIdentityResetCaseStudy()
}
}
}
Loading