0

Ok, so i'm trying to get a list element in another view to view more details and interact with it. Right now, This is a snippet of the code: (Note, this is in a Navigation View and that syntax is correct)

//below is listed before the body
@ObservedObject var jobViewModel: JobViewModel

//The rest is a snippet of the code in question
List{
                    ForEach(jobViewModel.jobs){ job in
                        let jobDate = ParserDate(date: job.date)
                        if job.completed == false && jobDate == comparisonDate{
                            let jobTime = ParserTime(time: job.date)
                            
                            NavigationLink(destination: dummy(job: job))
                                {
                                VStack(alignment: .leading){
                                    HStack{
                                        Text("Boat Name")
                                            Spacer()
                                                .frame(width: 50, height: 50)
                                        Text(job.boatName)
                                    }
                                //Text(job.boatID)
                        
                                    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)
                                    }
                                }
                            }
                        }
                    
                    }
                    
                }

This is the dummy view as of right now:

import SwiftUI

struct dummy: View {
    let job: Job
    
    
    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)
            }
        Text(job.boatID)

            /*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)
            }
        }
        
        
        
        
    }
}

struct dummy_Previews: PreviewProvider {
    static var previews: some View {
        dummy(job: Job[0])
    }
}

On the "dummy(job: Job[0])" line, i am getting this error: Type 'Job' has no member 'subscript'. I don't know where I'm going wrong. Any help is appreciated.

FrankDad
  • 23
  • 7
  • Job is a type(struct/class) not an object. Maybe you have a static variable inside Job definition that has an array of jobs and you wanted to fetch the first job. XCode is just saying that subscript(the square-bracket part) is not defined for the type "Job" – Aswath Mar 17 '21 at 05:04
  • I found the solution was to get rid of the preview portion of dummy(), but @Aswath , I get what you are saying. Job is a struct that gets put into an array of "Jobs". the input is from a firebase JSON DB. then it is outputted into the list. Thank you for your help. I'm new, so how to a upvote you? – FrankDad Mar 17 '21 at 05:06

0 Answers0