Skip to content

Commit 23390e5

Browse files
committed
adding file headers and updating other syntax
1 parent a021d93 commit 23390e5

File tree

12 files changed

+241
-99
lines changed

12 files changed

+241
-99
lines changed

firestore/FirestoreExample.xcodeproj/project.pbxproj

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@
2323
8DF1E3151EE72C4600192CDE /* LocalCollection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8DF1E3141EE72C4600192CDE /* LocalCollection.swift */; };
2424
8DF77E1A1EEB45E500CB2330 /* RestaurantDetailViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8DF77E191EEB45E500CB2330 /* RestaurantDetailViewController.swift */; };
2525
8DF77E1C1EEB645100CB2330 /* StarsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8DF77E1B1EEB645100CB2330 /* StarsView.swift */; };
26+
8E1E43B125F961EF00BC64D3 /* Restaurant+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8E1E43B025F961EF00BC64D3 /* Restaurant+Extension.swift */; };
2627
8E4C62D125E9CFE0001678A1 /* FirestoreSwiftUIExampleApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8E4C62D025E9CFE0001678A1 /* FirestoreSwiftUIExampleApp.swift */; };
27-
8E4C62D325E9CFE0001678A1 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8E4C62D225E9CFE0001678A1 /* ContentView.swift */; };
28+
8E4C62D325E9CFE0001678A1 /* RestaurantListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8E4C62D225E9CFE0001678A1 /* RestaurantListView.swift */; };
2829
8E4C62D525E9CFE1001678A1 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 8E4C62D425E9CFE1001678A1 /* Assets.xcassets */; };
2930
8E4C62D825E9CFE1001678A1 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 8E4C62D725E9CFE1001678A1 /* Preview Assets.xcassets */; };
3031
8E4C62E725E9D191001678A1 /* RestaurantItemView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8E4C62E625E9D191001678A1 /* RestaurantItemView.swift */; };
@@ -85,9 +86,10 @@
8586
8DF1E3141EE72C4600192CDE /* LocalCollection.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LocalCollection.swift; sourceTree = "<group>"; };
8687
8DF77E191EEB45E500CB2330 /* RestaurantDetailViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RestaurantDetailViewController.swift; sourceTree = "<group>"; };
8788
8DF77E1B1EEB645100CB2330 /* StarsView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StarsView.swift; sourceTree = "<group>"; };
89+
8E1E43B025F961EF00BC64D3 /* Restaurant+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Restaurant+Extension.swift"; sourceTree = "<group>"; };
8890
8E4C62CE25E9CFE0001678A1 /* FirestoreSwiftUIExample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = FirestoreSwiftUIExample.app; sourceTree = BUILT_PRODUCTS_DIR; };
8991
8E4C62D025E9CFE0001678A1 /* FirestoreSwiftUIExampleApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FirestoreSwiftUIExampleApp.swift; sourceTree = "<group>"; };
90-
8E4C62D225E9CFE0001678A1 /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = "<group>"; };
92+
8E4C62D225E9CFE0001678A1 /* RestaurantListView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RestaurantListView.swift; sourceTree = "<group>"; };
9193
8E4C62D425E9CFE1001678A1 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
9294
8E4C62D725E9CFE1001678A1 /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = "<group>"; };
9395
8E4C62D925E9CFE1001678A1 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
@@ -222,17 +224,26 @@
222224
path = FirestoreExampleTests;
223225
sourceTree = "<group>";
224226
};
227+
8E1E43AB25F9604B00BC64D3 /* Extensions */ = {
228+
isa = PBXGroup;
229+
children = (
230+
8E4C63D725F6D641001678A1 /* Firestore+Extension.swift */,
231+
8E1E43B025F961EF00BC64D3 /* Restaurant+Extension.swift */,
232+
);
233+
path = Extensions;
234+
sourceTree = "<group>";
235+
};
225236
8E4C62CF25E9CFE0001678A1 /* FirestoreSwiftUIExample */ = {
226237
isa = PBXGroup;
227238
children = (
239+
8E1E43AB25F9604B00BC64D3 /* Extensions */,
228240
8E4C637625EEF4B6001678A1 /* ViewModels */,
229241
8E4C634725EDB762001678A1 /* Model */,
230242
8E4C62E125E9D137001678A1 /* Views */,
231243
8E4C62D025E9CFE0001678A1 /* FirestoreSwiftUIExampleApp.swift */,
232244
8E4C62D425E9CFE1001678A1 /* Assets.xcassets */,
233245
8E4C62D925E9CFE1001678A1 /* Info.plist */,
234246
8E4C62D625E9CFE1001678A1 /* Preview Content */,
235-
8E4C63D725F6D641001678A1 /* Firestore+Extension.swift */,
236247
);
237248
path = FirestoreSwiftUIExample;
238249
sourceTree = "<group>";
@@ -248,7 +259,7 @@
248259
8E4C62E125E9D137001678A1 /* Views */ = {
249260
isa = PBXGroup;
250261
children = (
251-
8E4C62D225E9CFE0001678A1 /* ContentView.swift */,
262+
8E4C62D225E9CFE0001678A1 /* RestaurantListView.swift */,
252263
8E4C62E625E9D191001678A1 /* RestaurantItemView.swift */,
253264
8E4C63B125F05E76001678A1 /* StarsView.swift */,
254265
8E4C63DD25F6D879001678A1 /* ImageThumbnailView.swift */,
@@ -696,7 +707,8 @@
696707
isa = PBXSourcesBuildPhase;
697708
buildActionMask = 2147483647;
698709
files = (
699-
8E4C62D325E9CFE0001678A1 /* ContentView.swift in Sources */,
710+
8E1E43B125F961EF00BC64D3 /* Restaurant+Extension.swift in Sources */,
711+
8E4C62D325E9CFE0001678A1 /* RestaurantListView.swift in Sources */,
700712
8E4C634925EDB793001678A1 /* Restaurant.swift in Sources */,
701713
8E4C637825EEF4CA001678A1 /* RestaurantListViewModel.swift in Sources */,
702714
8E4C62D125E9CFE0001678A1 /* FirestoreSwiftUIExampleApp.swift in Sources */,

firestore/FirestoreSwiftUIExample/Firestore+Extension.swift renamed to firestore/FirestoreSwiftUIExample/Extensions/Firestore+Extension.swift

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,20 @@
22
// Firestore+Extension.swift
33
// FirestoreSwiftUIExample
44
//
5+
// Copyright (c) 2021 Google Inc.
6+
//
7+
// Licensed under the Apache License, Version 2.0 (the "License");
8+
// you may not use this file except in compliance with the License.
9+
// You may obtain a copy of the License at
10+
//
11+
// http://www.apache.org/licenses/LICENSE-2.0
12+
//
13+
// Unless required by applicable law or agreed to in writing, software
14+
// distributed under the License is distributed on an "AS IS" BASIS,
15+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
// See the License for the specific language governing permissions and
17+
// limitations under the License.
18+
//
519

620
import Firebase
721

@@ -43,15 +57,12 @@ extension Firestore {
4357
}
4458

4559
let batch = self.batch()
46-
//TODO: guard let user = Auth.auth().currentUser else { continue }
4760
var average: Float = 0
4861
for _ in 0 ..< 10 {
4962
let rating = Int(arc4random_uniform(5) + 1)
5063
average += Float(rating) / 10
5164
let text = rating > 3 ? "good" : "food was too spicy"
5265

53-
//TODO: userID: user.uid,
54-
//TODO: username: user.displayName ?? "Anonymous",
5566
let review = Review(
5667
rating: rating,
5768
userID: "1234567890",
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
//
2+
// Restaurant+Extension.swift
3+
// FirestoreSwiftUIExample
4+
//
5+
// Copyright (c) 2021 Google Inc.
6+
//
7+
// Licensed under the Apache License, Version 2.0 (the "License");
8+
// you may not use this file except in compliance with the License.
9+
// You may obtain a copy of the License at
10+
//
11+
// http://www.apache.org/licenses/LICENSE-2.0
12+
//
13+
// Unless required by applicable law or agreed to in writing, software
14+
// distributed under the License is distributed on an "AS IS" BASIS,
15+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
// See the License for the specific language governing permissions and
17+
// limitations under the License.
18+
//
19+
20+
import Firebase
21+
22+
extension Restaurant {
23+
static let cities = [
24+
"Albuquerque",
25+
"Arlington",
26+
"Atlanta",
27+
"Austin",
28+
"Baltimore",
29+
"Boston",
30+
"Charlotte",
31+
"Chicago",
32+
"Cleveland",
33+
"Colorado Springs",
34+
"Columbus",
35+
"Dallas",
36+
"Denver",
37+
"Detroit",
38+
"El Paso",
39+
"Fort Worth",
40+
"Fresno",
41+
"Houston",
42+
"Indianapolis",
43+
"Jacksonville",
44+
"Kansas City",
45+
"Las Vegas",
46+
"Long Beach",
47+
"Los Angeles",
48+
"Louisville",
49+
"Memphis",
50+
"Mesa",
51+
"Miami",
52+
"Milwaukee",
53+
"Nashville",
54+
"New York",
55+
"Oakland",
56+
"Oklahoma",
57+
"Omaha",
58+
"Philadelphia",
59+
"Phoenix",
60+
"Portland",
61+
"Raleigh",
62+
"Sacramento",
63+
"San Antonio",
64+
"San Diego",
65+
"San Francisco",
66+
"San Jose",
67+
"Tucson",
68+
"Tulsa",
69+
"Virginia Beach",
70+
"Washington"
71+
]
72+
73+
static let categories = [
74+
"Brunch", "Burgers", "Coffee", "Deli", "Dim Sum", "Indian", "Italian",
75+
"Mediterranean", "Mexican", "Pizza", "Ramen", "Sushi"
76+
]
77+
78+
static func imageURL(forName name: String) -> URL {
79+
let number = (abs(name.hashValue) % 22) + 1
80+
let URLString =
81+
"https://storage.googleapis.com/firestorequickstarts.appspot.com/food_\(number).png"
82+
return URL(string: URLString)!
83+
}
84+
85+
var imageURL: URL {
86+
return Restaurant.imageURL(forName: name)
87+
}
88+
}

firestore/FirestoreSwiftUIExample/FirestoreSwiftUIExampleApp.swift

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,33 @@
22
// FirestoreSwiftUIExampleApp.swift
33
// FirestoreSwiftUIExample
44
//
5+
// Copyright (c) 2021 Google Inc.
6+
//
7+
// Licensed under the Apache License, Version 2.0 (the "License");
8+
// you may not use this file except in compliance with the License.
9+
// You may obtain a copy of the License at
10+
//
11+
// http://www.apache.org/licenses/LICENSE-2.0
12+
//
13+
// Unless required by applicable law or agreed to in writing, software
14+
// distributed under the License is distributed on an "AS IS" BASIS,
15+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
// See the License for the specific language governing permissions and
17+
// limitations under the License.
18+
//
519

620
import SwiftUI
721
import Firebase
822

923
@main
1024
struct FirestoreSwiftUIExampleApp: App {
11-
1225
init() {
1326
FirebaseApp.configure()
1427
}
1528

1629
var body: some Scene {
1730
WindowGroup {
18-
ContentView()
31+
RestaurantListView()
1932
}
2033
}
2134
}

firestore/FirestoreSwiftUIExample/Model/Restaurant.swift

Lines changed: 14 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,20 @@
22
// Restaurant.swift
33
// FirestoreSwiftUIExample
44
//
5+
// Copyright (c) 2021 Google Inc.
6+
//
7+
// Licensed under the Apache License, Version 2.0 (the "License");
8+
// you may not use this file except in compliance with the License.
9+
// You may obtain a copy of the License at
10+
//
11+
// http://www.apache.org/licenses/LICENSE-2.0
12+
//
13+
// Unless required by applicable law or agreed to in writing, software
14+
// distributed under the License is distributed on an "AS IS" BASIS,
15+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
// See the License for the specific language governing permissions and
17+
// limitations under the License.
18+
//
519

620
import Firebase
721
import FirebaseFirestoreSwift
@@ -28,77 +42,7 @@ struct Restaurant: Identifiable, Codable {
2842
}
2943
}
3044

31-
extension Restaurant {
32-
33-
static let cities = [
34-
"Albuquerque",
35-
"Arlington",
36-
"Atlanta",
37-
"Austin",
38-
"Baltimore",
39-
"Boston",
40-
"Charlotte",
41-
"Chicago",
42-
"Cleveland",
43-
"Colorado Springs",
44-
"Columbus",
45-
"Dallas",
46-
"Denver",
47-
"Detroit",
48-
"El Paso",
49-
"Fort Worth",
50-
"Fresno",
51-
"Houston",
52-
"Indianapolis",
53-
"Jacksonville",
54-
"Kansas City",
55-
"Las Vegas",
56-
"Long Beach",
57-
"Los Angeles",
58-
"Louisville",
59-
"Memphis",
60-
"Mesa",
61-
"Miami",
62-
"Milwaukee",
63-
"Nashville",
64-
"New York",
65-
"Oakland",
66-
"Oklahoma",
67-
"Omaha",
68-
"Philadelphia",
69-
"Phoenix",
70-
"Portland",
71-
"Raleigh",
72-
"Sacramento",
73-
"San Antonio",
74-
"San Diego",
75-
"San Francisco",
76-
"San Jose",
77-
"Tucson",
78-
"Tulsa",
79-
"Virginia Beach",
80-
"Washington"
81-
]
82-
83-
static let categories = [
84-
"Brunch", "Burgers", "Coffee", "Deli", "Dim Sum", "Indian", "Italian",
85-
"Mediterranean", "Mexican", "Pizza", "Ramen", "Sushi"
86-
]
87-
88-
static func imageURL(forName name: String) -> URL {
89-
let number = (abs(name.hashValue) % 22) + 1
90-
let URLString =
91-
"https://storage.googleapis.com/firestorequickstarts.appspot.com/food_\(number).png"
92-
return URL(string: URLString)!
93-
}
94-
95-
var imageURL: URL {
96-
return Restaurant.imageURL(forName: name)
97-
}
98-
}
99-
10045
struct Review: Codable {
101-
10246
var rating: Int // Can also be enum
10347
var userID: String
10448
var username: String

firestore/FirestoreSwiftUIExample/ViewModels/RestaurantListViewModel.swift

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,25 @@
22
// RestaurantListViewModel.swift
33
// FirestoreSwiftUIExample
44
//
5+
// Copyright (c) 2021 Google Inc.
6+
//
7+
// Licensed under the Apache License, Version 2.0 (the "License");
8+
// you may not use this file except in compliance with the License.
9+
// You may obtain a copy of the License at
10+
//
11+
// http://www.apache.org/licenses/LICENSE-2.0
12+
//
13+
// Unless required by applicable law or agreed to in writing, software
14+
// distributed under the License is distributed on an "AS IS" BASIS,
15+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
// See the License for the specific language governing permissions and
17+
// limitations under the License.
18+
//
519

620
import Combine
721
import Firebase
822

923
class RestaurantListViewModel: ObservableObject {
10-
1124
@Published var restaurants = [Restaurant]()
1225
private var db = Firestore.firestore()
1326
private var listener: ListenerRegistration?

firestore/FirestoreSwiftUIExample/Views/ImageThumbnailView.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,20 @@
22
// ImageThumbnailView.swift
33
// FirestoreSwiftUIExample
44
//
5+
// Copyright (c) 2021 Google Inc.
6+
//
7+
// Licensed under the Apache License, Version 2.0 (the "License");
8+
// you may not use this file except in compliance with the License.
9+
// You may obtain a copy of the License at
10+
//
11+
// http://www.apache.org/licenses/LICENSE-2.0
12+
//
13+
// Unless required by applicable law or agreed to in writing, software
14+
// distributed under the License is distributed on an "AS IS" BASIS,
15+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
// See the License for the specific language governing permissions and
17+
// limitations under the License.
18+
//
519

620
import SwiftUI
721
import SDWebImageSwiftUI

0 commit comments

Comments
 (0)