0

This is what my code is looking like:

import SwiftUI

struct dummy: View {
    var job: Job
    @ObservedObject var jobViewModel: JobViewModel
    
    var body: some View {
        Text("Placeholder for job details, will not exists in production, please delete")
        VStack(alignment: .leading){
            HStack{
                Text("Boat Name")
                    Spacer()
                        .frame(width: 50, height: 50)
                Text(job.boatName)
            }
        

            /*HStack{
                Text("Job Time")
                    Spacer()
                        .frame(width: 50, height: 50)
                Text(jobTime)
            }*/
            HStack{
                Text("Job Type")
                    Spacer()
                        .frame(width: 50, height: 50)
                Text(job.job)
            }
            HStack{
                Text("Owner's Name")
                Spacer()
                    .frame(width: 50, height: 50)
                Text(job.ownerName)
                //Text(job.time)
            }
            
            Button("Complete Job"){
                jobViewModel.complete(job)
            }.frame(width: 200)
        }
        
        
        
        
    }
}



/*struct dummy_Previews: PreviewProvider {
    static var previews: some View {
        dummy(job: Job[0])
    }
}*/
//foundout to get rid of this from below:
//https://medium.com/swift-productions/create-list-navigation-using-swiftui-c63534355fb1
//If i didn't get rid of it, it would case issues

If I keep out the "PreviewProvider" it works, If i keep it in, it throws errors. I am building directly to a device every time I try the app. Do I need this so the ObservedObject works?

jnpdx
  • 45,847
  • 6
  • 64
  • 94
FrankDad
  • 23
  • 7

1 Answers1

0

If you want to use the preview functionality, you'll have to provide some sort of instance for the jobViewModel parameter.

You haven't shown the code to JobViewModel, but it may be as simple as doing:

dummy(job: Job(), jobViewModel: JobViewModel())

This is assuming Job and JobViewModel don't take any parameters -- if they do, you'll have to fill in values for those parameters as well. Xcode should be able to help you with autocomplete to show you what their parameters may be.

Not having a preview will not affect your ability to run your app in non-preview mode on the simulator or a device.

jnpdx
  • 45,847
  • 6
  • 64
  • 94
  • I see you’re new to SO. If this answered your question, you can click the green check mark to accept the answer. – jnpdx Mar 19 '21 at 05:55