So I have the function: storeFaveArtwork and I am trying to action it in my button further down using: self.storeFaveArtwork(artwork.id)
I am getting the error at the top in my
var body: some View {
The compiler is unable to type-check this expression in reasonable time; try breaking up the expression into distinct sub-expressions
Here is my code:
//
// ContentView.swift
// Shared
//
// Created by J*** B******* on 04/05/2022.
//
import SwiftUI
import Firebase
struct ContentView: View {
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")
}
}
@StateObject var viewAllArtwork = ViewAllArtwork()
var body: some View {
NavigationView {
List {
ForEach(viewAllArtwork.artworksData, id: \.self) { artwork in
NavigationLink(destination: ContentDetail(item: artwork)) {
HStack(alignment: .top, spacing: 3.0) {
URLImage(urlString: "https://melvynbiddulph.co.uk/images/gallery/"+artwork.file)
VStack(alignment: .leading, spacing: 3.0) {
if(artwork.id != nil){
Text("\(artwork.id)")
.font(.caption2)
.fontWeight(.bold)
.padding(2.0)
.foregroundColor(Color.gray)
.frame(width: 32.0, height: 32.0)
.shadow(radius: 20)
.overlay(RoundedRectangle(cornerRadius: 20)
.stroke(Color.gray, lineWidth: 2))
.background(Color.white, in: RoundedRectangle(cornerRadius: 20)
).position(x: -124, y: 20)
}
Text(artwork.title)
.font(.body)
.bold()
.frame(height: 36, alignment: .center)
.frame(maxWidth: .infinity)
HStack(spacing: 2) {
if (artwork.size != nil) {
Text(artwork.size)
.padding(4)
.font(.caption)
.background(Color.gray.opacity(0.2))
.cornerRadius(5)
.foregroundColor(Color.gray)
.frame(height: 25, alignment: .center)
.frame(maxWidth: .infinity)
}
if (artwork.price != 0) {
Text("£\(artwork.price)")
.fontWeight(.bold)
.padding(4)
.font(.caption)
.background(Color.green)
.cornerRadius(5)
.foregroundColor(Color.white)
.frame(width: .infinity)
}
Button {
self.storeFaveArtwork(artwork.id)
} label: {
HStack {
Spacer()
Text("Favourite")
.foregroundColor(.white)
.padding(.vertical, 10)
.font(.system(size: 14, weight: .semibold))
Spacer()
}.background(Color.blue)
}
Spacer()
.frame(width: 0.0, height: 60.0)
}
}
.frame(width: 150.0)
}
}
}
}
.navigationTitle("Artwork")
.onAppear {
viewAllArtwork.fetch()
}
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}