As the compiler says, you have put too much functionality into one View.
Even if the code is legal, it's not good practice.
Refactor, breaking up your functionality into smaller components.
You have made it a bit hard to be more specific, as your sample code includes a lot of external/undefined objects and functionality.
As a starting point, you could refactor the internal VStack and HStacks into separate Views.
You could factor out the Button, like this:
struct StoreFaveArtworkButtonView: View {
let artwork: Artwork
private func storeFaveArtwork(artwork: Artwork) {
guard let uid = FirebaseManager.shared.auth.currentUser?.uid else {
return
}
let artData = ["id": artwork.id, "uid": uid] as [String : Any]
FirebaseManager.shared.firestore.collection("favourites")
.document(uid).setData(artData) { err in
if let err = err {
print(err)
return
}
print("Success")
}
}
var body: some View {
Button {
storeFaveArtwork(artwork: artwork)
} label: {
HStack {
Spacer()
Text("Favourite")
.foregroundColor(.white)
.padding(.vertical, 10)
.font(.system(size: 14, weight: .semibold))
Spacer()
}.background(Color.blue)
}
}
}