I am making an attempt to name a perform I created which ought to fetch URLs from google cloud storage (firebase) when the view seems. I haven’t got any errors, however the code does not show any of my pictures. Have I missed a step within the building of my code? By the way in which the code proven under is self-contained inside the view. I plan on seperating issues as soon as I work out what is going on on.
This is the code I’ve to this point:
import SwiftUI
import FirebaseStorage
func testingCall(){
let _ = print("Check")
}
struct GalleryView: View {
@State var pictures = [String]()
func getDownloadURl() -> [String] {
var photoURLS = [String]()
let ref = Storage.storage().reference()
let storageReference = ref.baby("pictures/")
storageReference.listAll { (consequence, error) in
if let error = error {
print(error)
}
for merchandise in consequence!.gadgets {
//Listing storage reference
let storageLocation = String(describing: merchandise)
let gsReference = Storage.storage().reference(forURL: storageLocation)
// Fetch the obtain URL
gsReference.downloadURL { url, error in
if let error = error {
// Deal with any errors
print(error)
} else {
// Get the obtain URL for every merchandise storage location
print(url!)
print(sort(of: url!))
print(sort(of: url!.absoluteString))
photoURLS.append(url!.absoluteString)
print(photoURLS)
}
}
}
}
return photoURLS
}
var physique: some View {
NavigationView {
ScrollView {
LazyVGrid(columns: [
GridItem(.fixed(100)),
GridItem(.fixed(100)),
GridItem(.fixed(100))
], spacing: 12, content material:{
ForEach(pictures, id: .self){ photoURL in
HStack {
Spacer()
AsyncImage(url: URL(string:photoURL)){ end in
if let consequence = consequence.picture{
consequence
.resizable()
.body(width:124,peak:124)
}
}
Spacer()
}
.padding()
.background(Shade.purple)
}
})
}.navigationTitle("Gallery")
.onAppear{
pictures = self.getDownloadURl()
}
}
}
}
Thanks prematurely for any suggestions. I enormously admire it.