Learn Courses My Dashboard

IOS foundations lesson 4 challenge 6 - stuck

I am stuck and I cannot find the solution to this env object challenge
error: missing argument for parameter ‘person’ in call

the Xcode recommendations doesn’t solve the issue,

what am I doing wrong?
the code is pushed in this repo: GitHub - naticio/environment-object-module4-6

Doesn’t solve the problem or there’s a different problem?

Because the immediate problem is that ListView has a person member so you need to pass that in when you create the ListView.

sorry bad grammar

yes I removed the person var from List view, but still doesn’t compile

Please post your code instead of screenshots. If you place three backticks ``` on the line before and three backticks ``` on the line after your code, it will be formatted nicely for the forums and will allow other posters to copy/paste your code for testing instead of having to type it all in from scratch. It’s also easier to see on screen.

Can we see your User struct/class?

my bad

here is the tabView()

import SwiftUI

struct tabView: View {
    
    var body: some View {
        TabView {
            
            ListView()
                .tabItem {
                    VStack {
                        Image(systemName: "person.fill")
                        Text("People")
                    }
                }
            
            toggles()
                .tabItem {
                    VStack {
                        Image(systemName: "gear")
                        Text("Filters")
                    }
                }
        }
        .environmentObject(UserModel())
    }
}

struct tabView_Previews: PreviewProvider {
    static var previews: some View {
        tabView()
    }
}

then the ListView()

import SwiftUI

struct ListView: View {
    @EnvironmentObject var model: UserModel
    //var person: User esta studpida var caused the issue
    
    var body: some View {
        
        VStack {
            Text("People")
                .font(.title)
                .bold()
            
            List(model.usuarios) { morro in
                VStack(alignment: .leading) {
                    Text(morro.name)
                    Text(morro.address)
                    Text(morro.company)
                    Text(morro.YOE)
                }
            }
        }
    }
}

struct ListView_Previews: PreviewProvider {
    static var previews: some View {
        ListView()
    }
}

ViewModel

import Foundation

class UserModel: ObservableObject {
    
    @Published var usuarios = [User]()
    
    @Published var showName = true
    @Published var showAddress = true
    @Published var showCompany = true
    @Published var showYears = true
    
    
    init() {
        self.usuarios = DataService.getLocalData()
        
    }
}

User Model

import Foundation
//build a view model that holds a list of people and the current user’s preferences. Access the model in the views by using the EnvironmentObject modifier.
class User: Identifiable, Decodable {
    var id:UUID?
    var name:String
    var address:String
    var company: String
    var YOE:Int
}

Here’s the problem:

Text(morro.YOE)

morro.YOE is an Int but the version of the Text element that you are using requires a String.

Since there is no version of Text that takes an Int, you need to do this:

Text(String(morro.YOE))

ay ay ay I feel embarrassed :face_with_raised_eyebrow:

I guess studying when tired is not the best combo! thank YOU Patrick!