Skip to content

Commit 326f87f

Browse files
committed
Revise applyEdits
1 parent 1737a28 commit 326f87f

File tree

3 files changed

+63
-30
lines changed

3 files changed

+63
-30
lines changed

Examples/Examples/FeatureFormExampleView.swift

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -89,30 +89,41 @@ extension FeatureFormExampleView {
8989
defer { editsAreBeingApplied = false }
9090

9191
for table in editedTables {
92+
guard editedTables.contains(where: { $0 === table }) else {
93+
// Edits to this table were already batch-applied to the
94+
// geodatabase in a previous iteration.
95+
break
96+
}
9297
guard let database = table.serviceGeodatabase else {
9398
throw .other("No geodatabase found.")
9499
}
95100
guard database.hasLocalEdits else {
96101
throw .other("No database edits found.")
97102
}
98-
let resultErrors: [Error]
99103
do {
100-
if let serviceInfo = database.serviceInfo, serviceInfo.canUseServiceGeodatabaseApplyEdits {
104+
let makeSubmissionError: (_ errors: [Error]) -> SubmissionError = { errors in
105+
.other("Apply edits returned ^[\(errors.count) error](inflect: true).")
106+
}
107+
if database.serviceInfo?.canUseServiceGeodatabaseApplyEdits ?? false {
101108
let featureTableEditResults = try await database.applyEdits()
102-
resultErrors = featureTableEditResults.flatMap(\.editResults.errors)
109+
let resultErrors = featureTableEditResults.flatMap(\.editResults.errors)
110+
if resultErrors.isEmpty {
111+
editedTables.removeAll { $0.serviceGeodatabase === database }
112+
} else {
113+
throw makeSubmissionError(resultErrors)
114+
}
103115
} else {
104116
let featureEditResults = try await table.applyEdits()
105-
resultErrors = featureEditResults.errors
117+
let resultErrors = featureEditResults.errors
118+
if resultErrors.isEmpty {
119+
editedTables.removeAll { $0 === table }
120+
} else {
121+
throw makeSubmissionError(resultErrors)
122+
}
106123
}
107124
} catch {
108125
throw .anyError(error)
109126
}
110-
editedTables.removeAll { $0.tableName == table.tableName }
111-
if !resultErrors.isEmpty {
112-
throw .other(
113-
"Apply edits returned ^[\(resultErrors.count) error](inflect: true)."
114-
)
115-
}
116127
}
117128
}
118129

Sources/ArcGISToolkit/Documentation.docc/Resources/FeatureFormView/FeatureFormViewTutorialSection1Step4.swift

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -56,30 +56,41 @@ extension FeatureFormExampleView {
5656
defer { editsAreBeingApplied = false }
5757

5858
for table in editedTables {
59+
guard editedTables.contains(where: { $0 === table }) else {
60+
// Edits to this table were already batch-applied to the
61+
// geodatabase in a previous iteration.
62+
break
63+
}
5964
guard let database = table.serviceGeodatabase else {
6065
throw .other("No geodatabase found.")
6166
}
6267
guard database.hasLocalEdits else {
6368
throw .other("No database edits found.")
6469
}
65-
let resultErrors: [Error]
6670
do {
67-
if let serviceInfo = database.serviceInfo, serviceInfo.canUseServiceGeodatabaseApplyEdits {
71+
let makeSubmissionError: (_ errors: [Error]) -> SubmissionError = { errors in
72+
.other("Apply edits returned ^[\(errors.count) error](inflect: true).")
73+
}
74+
if database.serviceInfo?.canUseServiceGeodatabaseApplyEdits ?? false {
6875
let featureTableEditResults = try await database.applyEdits()
69-
resultErrors = featureTableEditResults.flatMap(\.editResults.errors)
76+
let resultErrors = featureTableEditResults.flatMap(\.editResults.errors)
77+
if resultErrors.isEmpty {
78+
editedTables.removeAll { $0.serviceGeodatabase === database }
79+
} else {
80+
throw makeSubmissionError(resultErrors)
81+
}
7082
} else {
7183
let featureEditResults = try await table.applyEdits()
72-
resultErrors = featureEditResults.errors
84+
let resultErrors = featureEditResults.errors
85+
if resultErrors.isEmpty {
86+
editedTables.removeAll { $0 === table }
87+
} else {
88+
throw makeSubmissionError(resultErrors)
89+
}
7390
}
7491
} catch {
7592
throw .anyError(error)
7693
}
77-
editedTables.removeAll { $0.tableName == table.tableName }
78-
if !resultErrors.isEmpty {
79-
throw .other(
80-
"Apply edits returned ^[\(resultErrors.count) error](inflect: true)."
81-
)
82-
}
8394
}
8495
}
8596

Sources/ArcGISToolkit/Documentation.docc/Resources/FeatureFormView/FeatureFormViewTutorialSection1Step5.swift

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -71,30 +71,41 @@ extension FeatureFormExampleView {
7171
defer { editsAreBeingApplied = false }
7272

7373
for table in editedTables {
74+
guard editedTables.contains(where: { $0 === table }) else {
75+
// Edits to this table were already batch-applied to the
76+
// geodatabase in a previous iteration.
77+
break
78+
}
7479
guard let database = table.serviceGeodatabase else {
7580
throw .other("No geodatabase found.")
7681
}
7782
guard database.hasLocalEdits else {
7883
throw .other("No database edits found.")
7984
}
80-
let resultErrors: [Error]
8185
do {
82-
if let serviceInfo = database.serviceInfo, serviceInfo.canUseServiceGeodatabaseApplyEdits {
86+
let makeSubmissionError: (_ errors: [Error]) -> SubmissionError = { errors in
87+
.other("Apply edits returned ^[\(errors.count) error](inflect: true).")
88+
}
89+
if database.serviceInfo?.canUseServiceGeodatabaseApplyEdits ?? false {
8390
let featureTableEditResults = try await database.applyEdits()
84-
resultErrors = featureTableEditResults.flatMap(\.editResults.errors)
91+
let resultErrors = featureTableEditResults.flatMap(\.editResults.errors)
92+
if resultErrors.isEmpty {
93+
editedTables.removeAll { $0.serviceGeodatabase === database }
94+
} else {
95+
throw makeSubmissionError(resultErrors)
96+
}
8597
} else {
8698
let featureEditResults = try await table.applyEdits()
87-
resultErrors = featureEditResults.errors
99+
let resultErrors = featureEditResults.errors
100+
if resultErrors.isEmpty {
101+
editedTables.removeAll { $0 === table }
102+
} else {
103+
throw makeSubmissionError(resultErrors)
104+
}
88105
}
89106
} catch {
90107
throw .anyError(error)
91108
}
92-
editedTables.removeAll { $0.tableName == table.tableName }
93-
if !resultErrors.isEmpty {
94-
throw .other(
95-
"Apply edits returned ^[\(resultErrors.count) error](inflect: true)."
96-
)
97-
}
98109
}
99110
}
100111

0 commit comments

Comments
 (0)