-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCRUD.swift
136 lines (136 loc) · 4.04 KB
/
CRUD.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
////
//// CRUD.swift
//// Demo
////
//// Created by iMac on 30/04/20.
//// Copyright © 2020 iMac. All rights reserved.
////
//
import Foundation
//
////
//// ViewController.swift
//// crud-demo
////
//// This source code is for this tutorial: https://youtu.be/qA9L3_cK9Z0
//// Before using, connect your own Firestore database instead of using mine.
//// I've removed my config file so you'll have to sign up for Firebase and add your own GoogleService-Info.plist to Xcode.
////
//
//import UIKit
//import Firebase
//
//class ViewController: UIViewController {
//
// override func viewDidLoad() {
// super.viewDidLoad()
// // Do any additional setup after loading the view.
//
// let db = Firestore.firestore()
//
// // Adding a document
// // See: https://firebase.google.com/docs/firestore/manage-data/add-data
// db.collection("wine")
// .addDocument(data: ["year":2017,
// "type":"pinot-noir",
// "label":"Peller Estates"])
//
// // Getting the document ID
// let newDocument = db.collection("wine").document()
// newDocument.setData(["year":2017,
// "type":"pinot-noir",
// "label":"Peller Estates",
// "id":newDocument.documentID])
//
//
// // Adding a document with a specific document ID / Or Replacing the data for a specific document ID
// db.collection("wine")
// .document("pinot-noir-2017")
// .setData(["hello":"new data",
// "newKey":"newValue"], merge: true)
//
// // Updating a specific document ID
// db.collection("wine")
// .document("stoneypath-cab-2017")
// .setData(["year":2017,
// "type":"cab",
// "label":"Stoney Path"], merge:true)
//
// // Detecting errors (Use the completion handler)
// db.collection("wine")
// .addDocument(data: ["test":"test"]) { (error) in
//
// if error != nil {
// // There was an error
// }
// else {
// // error is nil.. so operation completed successfully
// }
// }
//
// // Delete a document
// // See: https://firebase.google.com/docs/firestore/manage-data/delete-data
// db.collection("wine")
// .document("stoneypath-cab-2017").delete()
//
// // Delete a field
// db.collection("wine")
// .document("stoneypath-cab-2017")
// .updateData(["type":FieldValue.delete()])
//
// // Detect for errors, use completion parameter
// db.collection("wine")
// .document("pinot-noir-2017")
// .delete { (error) in
//
// if error != nil {
// // We have an error
// }
// else {
// // Delete was sucessful
// }
// }
//
// // Read a specific document
// // See: https://firebase.google.com/docs/firestore/query-data/get-data
// db.collection("wine")
// .document("pinot-noir-2017")
// .getDocument { (document, error) in
//
// // Check for error
// if error == nil {
//
// // Check that this document exists
// if document != nil && document!.exists {
//
// let documentData = document!.data()
//
// }
//
// }
//
// }
// // Getting all documents from a collection
// db.collection("wine")
// .getDocuments { (snapshot, error) in
//
// if error == nil && snapshot != nil {
//
// for document in snapshot!.documents {
//
// let documentData = document.data()
//
// }
//
// }
// }
//
// // Getting a subset of documents
// db.collection("wine").whereField("year", isEqualTo: 2017).getDocuments { (snapshot, error) in
// <#code#>
// }
// }
//
//
//}
//