I can't implement variable to another class

struct History: View {

var busId : String


var body: some View {

ZStack{

ScrollView(.vertical, showsIndicators: false){

VStack(alignment: .leading){

Text("Something")

}

}

}

}


class getHistory: ObservableObject {

@Published var data = [history]()

init() {


let db = Firestore.firestore()

db.collection("Bus").document(/* Here i want to implement busId, but i can't. Please help me */).collection("Tanggal").addSnapshotListener{(snap, error) in

}

}

}

}


struct history: Identifiable {

var id : String

var day : String

}

Replies

You are probably new to the forum. Some good practices:

- Post the question in the right section. This is SwiftUI, not Swift.

=> Move your post there


- Edit code with the formatter tool (<>)

=> like this

struct history: Identifiable {
    var id : String
    var day : String
}


- Explain in detail the point:

what you want to achieve precisely

what you get (error messages ? no output ?)

the context (here using Firebase)

=> Just a comment to search in the code is not adequate

struct History: View {
    var busId : String
 
    var body: some View {
        ZStack{
            ScrollView(.vertical, showsIndicators: false){
                VStack(alignment: .leading) {
                   Text("Something")
                }
             
            }
        }
    }
 
    class getHistory: ObservableObject {
     
        @Published var data = [history]()
        init() {
            let db = Firestore.firestore()
            db.collection("Bus").document().collection("Tanggal").addSnapshotListener{(snap, error) in
               
            }
        }
    }
}

struct history: Identifiable {
    var id : String
    var day : String
}


You said on line 19::

/* Here i want to implement busId, but i can't. Please help me */


The best is probably for you to read this:

https://stackoverflow.com/questions/59216575/swiftui-simple-firestore-query-display-results


Don't try to do everything at once. You'll create a snapshot later with this:

https://stackoverflow.com/questions/58660130/how-do-i-get-data-out-of-a-firebase-snapshot-in-swift-using-a-function-in-a-stru