How to create a DetailView in SwiftUI?

I'm getting: Cannot find 'viewAllArtwork' in scope

my detail view:

import SwiftUI

struct ArtworkDetailView: View {
  @StateObject var viewAllArtwork = ViewAllArtwork()
  var artwork: Artwork
   
  var body: some View {
    Text(artwork.title)
  }
}

struct ArtworkDetailView_Previews: PreviewProvider {
  static var previews: some View {
    ArtworkDetailView(artwork: viewAllArtwork.artworksData[0])
  }
}

and my Artwork Views:

import SwiftUI

struct ArtworkView: View {
  @StateObject var singleArtwork = SingleArtwork()
  var body: some View {
    NavigationView {
      List {
        ForEach(singleArtwork.artworksData, id: \.self) { artwork in
          HStack(spacing: 8) {
            URLImage(urlString: "https://melvynbiddulph.co.uk/images/gallery/"+artwork.file)
            Text(artwork.title)
              .bold()
            if (artwork.size != nil) {
              Text(artwork.size)
            }
          }
        }
      }
      .navigationTitle("Single Artwork")
      .onAppear {
        singleArtwork.fetch()
      }
    }
  }
}

struct ArtworkView_Previews: PreviewProvider {
  static var previews: some View {
    ArtworkView()
  }
}

and to get the data for this:

import Foundation

import SwiftUI

class ViewAllArtwork: ObservableObject {
  @Published var artworksData: [Artwork] = []
  func fetch() {
    guard let url = URL(string: "https://melvynbiddulph.co.uk/api/artwork") else {
      return
    }
     
    let task = URLSession.shared.dataTask(with: url) { data, response, error in
      guard let data = data, error == nil else {
        return
      }
       
      //convert to JSON
      do {
        let artworksData = try JSONDecoder().decode([Artwork].self, from: data)
        DispatchQueue.main.async {
          self.artworksData = artworksData
        }
      } catch {
        print(error)
      }
    }
    task.resume()
  }
}

Please help

You have defined "viewAllArtwork" in "ArtworkDetailView"
You are trying to reference it in "ArtworkDetailView_Previews", which is a completely different thing.

Hence the error message.

In ArtworkDetailView_Previews, you need to create a single Artwork, and pass it to the ArtworkDetailView.
You have not included the code for Artwork, so I can't suggest how you create that.

Typically, it would be something like:

ArtworkDetailView(artwork: Artwork())

I'm all confused, I moved the the ViewAllArtwork to the same folder and called viewAllArtwork() - still the same

How to create a DetailView in SwiftUI?
 
 
Q