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.3k
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
844
Jan ’22
Update tableView in swift 5
I'm pulling data from Firestore and listing it in my table. However, according to the conditions in the data I have taken, the color or touch of the data in my table must change. In the codes I wrote, this works, but sometimes the data does not come and naturally the table is not updated. Or when I scroll the list the data comes and the list is updated. How can I do this without problems? I am posting my codes and screenshot. when i choose the date not working when i select a date again it shows the error "[UICollectionViewRecursion] cv == 0x1088d4600 Disabling recursion trigger logging" when no data is received. please someone help me by changing my codes or showing me a different way.
3
0
1k
Nov ’21