-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFirebase.swift
80 lines (66 loc) · 2.3 KB
/
Firebase.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
//
// Firebase.swift
// bigfantv
//
// Created by Ganesh on 14/07/20.
// Copyright © 2020 Ganesh. All rights reserved.
//
import UIKit
import Firebase
import SDWebImage
import FirebaseFirestore
class Firebase: UIViewController {
@IBOutlet var ImgSample: UIImageView!
override func viewDidLoad() {
super.viewDidLoad()
ImgSample.sd_setImage(with: URL(string: "https://d73o4i22vgk5h.cloudfront.net/45921/public/public/system/studio_banner/45921/original/Big_FAN_Promo_web.jpg"), completed: nil)
// AddData()
// update()
// customClassGetDocument()
}
func AddData()
{
let badRestaurantData: [String : Any] =
[
"country": "Indiawddd"
]
guard let userid = UserDefaults.standard.value(forKey: "id")as? String else {return}
Firestore.firestore().collection("Country").document(userid).setData(badRestaurantData) { (error) in
if let error = error {
print("Could not Add Data: \(error)")
} else {
print("Data added succesfully")
}
}
}
func update()
{
guard let userid = UserDefaults.standard.value(forKey: "id")as? String else {return}
Firestore.firestore().collection("Country").document(userid).updateData([
"country": "India"
]) { err in
if let err = err {
print("Error updating document: \(err)")
} else {
print("Data successfully updated")
}
}
}
private func customClassGetDocument() {
// [START custom_type]
guard let userid = UserDefaults.standard.value(forKey: "id")as? String else {return}
let docRef = Firestore.firestore().collection("Country").document(userid)
docRef.getDocument { (document, error) in
if let err = error
{
print("Error fetch document: \(err)")
}
else {
guard let data = document?.data() else {return}
print(data["country"])
}
//print(document?.data())
//print(error)
}
}
}