I know its a really simple question but I'm just stuck on it atm so any advice would be greatly appreciated as I am new to SwiftUI.
I am trying to download text from firebase and render it to the view but I keep getting an out of range error:
Fatal error: Index out of range: file Swift/ContiguousArrayBuffer.swift, line 444
The code is as follows:
var body: some View{
ZStack {
if fetch.loading == false {
LoadingView()
}
else{
Text(names[0])
.bold()
}
}
.onAppear {
self.fetch.longTask()
}
}
Here is the Fetch Content Page:
@Published var loading = false
func longTask() {
DispatchQueue.main.asyncAfter(deadline: .now()) {
let db = Firestore.firestore()
db.collection("Flipside").getDocuments { (snapshot, err) in
if let err = err {
print("Error getting documents: \(err)")
return
} else {
for document in snapshot!.documents {
let name = document.get("Name") as! String
let description = document.get("Description") as! String
//name = items[doc]
print("Names: ", name)
print("Descriptions: ", description)
names.append(name)
descriptions.append(description)
}
}
}
self.loading = true
}
}
So basically when the view appears, get the data from Firebase when the data has downloaded display the menuPage()
until then show the Loading Data
text.
Any help is welcome!