Post

Replies

Boosts

Views

Activity

Get data from firestore with swiftui
I have a class where I get data from firebase. But I can't get it exactly as I want, for example document("abc" ) here I need to get the name "abc" from another place, different name may come according to each click. I can't assign this to the class I'm getting the data from, can you help me? import Firebase struct StadiumNameView: View { var body: some View { VStack{ List(stadiumnameeeee) { i in NavigationLink(destination: SelectedStadiumView(selectedStadium:i.name)){ Text(i.name) } } } } } struct StadiumNameView_Previews: PreviewProvider { static var previews: some View { StadiumNameView() } } I need to pass the "i.name" here to the following class. import Firebase class UserInfoModel : ObservableObject { @Published var city="" @Published var email="" @Published var name="" @Published var surname="" @Published var phone="" @Published var town="" @Published var type="" @Published var id="" @Published var birthday="" @Published var favStadium=[String]() init(){ let db=Firestore.firestore() db.collection("Users").document(Auth.auth().currentUser!.uid).addSnapshotListener { (snapshot, error) in if error == nil { if let city=snapshot?.get("City") as? String { self.city=city } if let email=snapshot?.get("Email") as? String { self.email=email } if let name=snapshot?.get("Name") as? String { self.name=name } if let surname=snapshot?.get("Surname") as? String { self.surname=surname } if let phonenumber=snapshot?.get("Phone") as? String { self.phone=phonenumber } if let town=snapshot?.get("Town") as? String { self.town=town } if let type=snapshot?.get("Type") as? String { self.type=type } if let id=snapshot?.get("User") as? String { self.id=id } if let birthday=snapshot?.get("DateofBirth") as? String { self.birthday=birthday } if let favStadiums=snapshot?.get("FavoriteStadiums") as? [String]{ self.favStadium=favStadiums } } } } }
0
0
1.4k
Jan ’22
SwiftUI NavigationLink in list with Firebase
I have 2 lists on different screens. It sorts the other list according to the data in the list I printed first. For example, if "name" is written in the list, it pulls data from firebase and lists it according to the "name" data in the other list. But the first time I click on the list, the empty list comes up and the next time I click, the data comes up according to the first click. @ObservedObject var findStadium=FindStadium() @State var selectedTown="" @State var stadiumNameArray=[String]() var body: some View { NavigationView { List(findStadium.townArray){ towns in NavigationLink(destination: StadiumNameView().onAppear{ selectedTown=towns.town let firestoreDatabase=Firestore.firestore() firestoreDatabase.collection("Stadiums").order(by: "Name",descending: false).addSnapshotListener { (snapshot, error) in if error != nil { print(error?.localizedDescription ?? "Error") } else { if snapshot?.isEmpty != true && snapshot != nil { stadiumnameeeee.removeAll(keepingCapacity: false) print(stadiumnameeeee) for document in snapshot!.documents { if let Name = document.get("Town") as? String { if Name==self.selectedTown { let stadiumName=document.get("Name") as! String self.stadiumNameArray.append(stadiumName) stadiumnameeeee.append(stadiumName) print(stadiumName) print(stadiumnameeeee) } } } } } } }) { Text(towns.town) } } .navigationBarTitle("İstanbul",displayMode:.large) //başka şehirler eklenirse düzenle } }} and other view var body: some View { VStack{ List(stadiumnameeeee,id:\.self) { i in NavigationLink(destination: SelectedStadiumView()){ Text(i) } } } }} where am i doing wrong? please help!
0
0
887
Jan ’22
Get data from firestore with swiftui
I have a class where I get data from firebase. But I can't get it exactly as I want, for example document("abc" ) here I need to get the name "abc" from another place, different name may come according to each click. I can't assign this to the class I'm getting the data from, can you help me? import Firebase struct StadiumNameView: View { var body: some View { VStack{ List(stadiumnameeeee) { i in NavigationLink(destination: SelectedStadiumView(selectedStadium:i.name)){ Text(i.name) } } } } } struct StadiumNameView_Previews: PreviewProvider { static var previews: some View { StadiumNameView() } } I need to pass the "i.name" here to the following class. import Firebase class UserInfoModel : ObservableObject { @Published var city="" @Published var email="" @Published var name="" @Published var surname="" @Published var phone="" @Published var town="" @Published var type="" @Published var id="" @Published var birthday="" @Published var favStadium=[String]() init(){ let db=Firestore.firestore() db.collection("Users").document(Auth.auth().currentUser!.uid).addSnapshotListener { (snapshot, error) in if error == nil { if let city=snapshot?.get("City") as? String { self.city=city } if let email=snapshot?.get("Email") as? String { self.email=email } if let name=snapshot?.get("Name") as? String { self.name=name } if let surname=snapshot?.get("Surname") as? String { self.surname=surname } if let phonenumber=snapshot?.get("Phone") as? String { self.phone=phonenumber } if let town=snapshot?.get("Town") as? String { self.town=town } if let type=snapshot?.get("Type") as? String { self.type=type } if let id=snapshot?.get("User") as? String { self.id=id } if let birthday=snapshot?.get("DateofBirth") as? String { self.birthday=birthday } if let favStadiums=snapshot?.get("FavoriteStadiums") as? [String]{ self.favStadium=favStadiums } } } } }
Replies
0
Boosts
0
Views
1.4k
Activity
Jan ’22
SwiftUI NavigationLink in list with Firebase
I have 2 lists on different screens. It sorts the other list according to the data in the list I printed first. For example, if "name" is written in the list, it pulls data from firebase and lists it according to the "name" data in the other list. But the first time I click on the list, the empty list comes up and the next time I click, the data comes up according to the first click. @ObservedObject var findStadium=FindStadium() @State var selectedTown="" @State var stadiumNameArray=[String]() var body: some View { NavigationView { List(findStadium.townArray){ towns in NavigationLink(destination: StadiumNameView().onAppear{ selectedTown=towns.town let firestoreDatabase=Firestore.firestore() firestoreDatabase.collection("Stadiums").order(by: "Name",descending: false).addSnapshotListener { (snapshot, error) in if error != nil { print(error?.localizedDescription ?? "Error") } else { if snapshot?.isEmpty != true && snapshot != nil { stadiumnameeeee.removeAll(keepingCapacity: false) print(stadiumnameeeee) for document in snapshot!.documents { if let Name = document.get("Town") as? String { if Name==self.selectedTown { let stadiumName=document.get("Name") as! String self.stadiumNameArray.append(stadiumName) stadiumnameeeee.append(stadiumName) print(stadiumName) print(stadiumnameeeee) } } } } } } }) { Text(towns.town) } } .navigationBarTitle("İstanbul",displayMode:.large) //başka şehirler eklenirse düzenle } }} and other view var body: some View { VStack{ List(stadiumnameeeee,id:\.self) { i in NavigationLink(destination: SelectedStadiumView()){ Text(i) } } } }} where am i doing wrong? please help!
Replies
0
Boosts
0
Views
887
Activity
Jan ’22