Skip to content

Commit 80197e0

Browse files
committed
Update code to match changes in firebase/firebase-ios-sdk#9101
1 parent 73ed490 commit 80197e0

File tree

5 files changed

+23
-46
lines changed

5 files changed

+23
-46
lines changed

FirestoreCodableSamples.xcodeproj/project.pbxproj

+10
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
887A4A7F2608EA7E009ACBB1 /* MappingEnumsScreen.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MappingEnumsScreen.swift; sourceTree = "<group>"; };
6161
887DD2B325C47A23003F7A99 /* Book.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Book.swift; sourceTree = "<group>"; };
6262
888F881325C46A9C00DCE039 /* GoogleService-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "GoogleService-Info.plist"; sourceTree = "<group>"; };
63+
88BBF4452790B29800A6D1A7 /* firebase-ios-sdk */ = {isa = PBXFileReference; lastKnownFileType = wrapper; name = "firebase-ios-sdk"; path = "../../../Projects/Incubation/Firebase/firebase-documentsnapshot-typing/firebase-ios-sdk"; sourceTree = "<group>"; };
6364
/* End PBXFileReference section */
6465

6566
/* Begin PBXFrameworksBuildPhase section */
@@ -78,6 +79,7 @@
7879
8845BD6D25C46965002AEC45 = {
7980
isa = PBXGroup;
8081
children = (
82+
88BBF4442790B29800A6D1A7 /* Packages */,
8183
8845BD7825C46965002AEC45 /* FirestoreCodableSamples */,
8284
8845BD7725C46965002AEC45 /* Products */,
8385
887DD2AD25C479FD003F7A99 /* Frameworks */,
@@ -178,6 +180,14 @@
178180
path = ViewModels;
179181
sourceTree = "<group>";
180182
};
183+
88BBF4442790B29800A6D1A7 /* Packages */ = {
184+
isa = PBXGroup;
185+
children = (
186+
88BBF4452790B29800A6D1A7 /* firebase-ios-sdk */,
187+
);
188+
name = Packages;
189+
sourceTree = "<group>";
190+
};
181191
/* End PBXGroup section */
182192

183193
/* Begin PBXNativeTarget section */

FirestoreCodableSamples/Screens/CustomizeMappingScreen.swift

+3-11
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,9 @@ class CustomizeMappingViewModel: ObservableObject {
3838

3939
switch result {
4040
case .success(let programmingLanguage):
41-
if let programmingLanguage = programmingLanguage {
42-
// A ProgrammingLanguage value was successfully initialized from the DocumentSnapshot.
43-
self?.errorMessage = nil
44-
return programmingLanguage
45-
}
46-
else {
47-
// A nil value was successfully initialized from the DocumentSnapshot,
48-
// or the DocumentSnapshot was nil.
49-
self?.errorMessage = "Document doesn't exist."
50-
return nil
51-
}
41+
// A ProgrammingLanguage value was successfully initialized from the DocumentSnapshot.
42+
self?.errorMessage = nil
43+
return programmingLanguage
5244
case .failure(let error):
5345
// A Book value could not be initialized from the DocumentSnapshot.
5446
switch error {

FirestoreCodableSamples/Screens/MappingColorsScreen.swift

+4-13
Original file line numberDiff line numberDiff line change
@@ -35,22 +35,13 @@ class MappingColorsViewModel: ObservableObject {
3535

3636
self?.colorEntries = documents.compactMap { queryDocumentSnapshot in
3737
let result = Result { try queryDocumentSnapshot.data(as: ColorEntry.self) }
38-
3938
switch result {
4039
case .success(let colorEntry):
41-
if let colorEntry = colorEntry {
42-
// A ColorEntry value was successfully initialized from the DocumentSnapshot.
43-
self?.errorMessage = nil
44-
return colorEntry
45-
}
46-
else {
47-
// A nil value was successfully initialized from the DocumentSnapshot,
48-
// or the DocumentSnapshot was nil.
49-
self?.errorMessage = "Document doesn't exist."
50-
return nil
51-
}
40+
// A ColorEntry value was successfully initialized from the DocumentSnapshot.
41+
self?.errorMessage = nil
42+
return colorEntry
5243
case .failure(let error):
53-
// A Book value could not be initialized from the DocumentSnapshot.
44+
// A ColorEntry value could not be initialized from the DocumentSnapshot.
5445
switch error {
5546
case DecodingError.typeMismatch(_, let context):
5647
self?.errorMessage = "\(error.localizedDescription): \(context.debugDescription)"

FirestoreCodableSamples/Screens/MappingEnumsScreen.swift

+3-11
Original file line numberDiff line numberDiff line change
@@ -76,17 +76,9 @@ class MappingEnumsViewModel: ObservableObject {
7676

7777
switch result {
7878
case .success(let article):
79-
if let article = article {
80-
// An Article value was successfully initialized from the DocumentSnapshot.
81-
self?.errorMessage = nil
82-
return article
83-
}
84-
else {
85-
// A nil value was successfully initialized from the DocumentSnapshot,
86-
// or the DocumentSnapshot was nil.
87-
self?.errorMessage = "Document doesn't exist."
88-
return nil
89-
}
79+
// An Article value was successfully initialized from the DocumentSnapshot.
80+
self?.errorMessage = nil
81+
return article
9082
case .failure(let error):
9183
// An Article value could not be initialized from the DocumentSnapshot.
9284
switch error {

FirestoreCodableSamples/Screens/MappingGeoPointsScreen.swift

+3-11
Original file line numberDiff line numberDiff line change
@@ -82,17 +82,9 @@ class MappingGeoPointsViewModel: ObservableObject {
8282

8383
switch result {
8484
case .success(let office):
85-
if let office = office {
86-
// An Office value was successfully initialized from the DocumentSnapshot.
87-
self?.errorMessage = nil
88-
return office
89-
}
90-
else {
91-
// A nil value was successfully initialized from the DocumentSnapshot,
92-
// or the DocumentSnapshot was nil.
93-
self?.errorMessage = "Document doesn't exist."
94-
return nil
95-
}
85+
// An Office value was successfully initialized from the DocumentSnapshot.
86+
self?.errorMessage = nil
87+
return office
9688
case .failure(let error):
9789
// An Office value could not be initialized from the DocumentSnapshot.
9890
switch error {

0 commit comments

Comments
 (0)