Can't modify a model's property inside a SwiftUI View

Error happens on the following line: merchant.distanceToCustomer = 0.00

Notice how I make 2 API calls and also a Geolocation call to get latitude/longitude. I may be approaching all this incorrectly. Help would be appreciated!

Merchant model:
    struct Merchant: Identifiable, Hashable {
    let id: Int
    let name: String
    let email: String
    let phoneNumber: String
    let description: String
    let vendorImageUri: String
    let address1: String
    let town: String
    let city: String
    let stateAbbreviation: String
    let zipPostalCode: String
    let latitude: Double
    let longitude: Double
    let createdOn: Date
    let updatedOn: Date
    let hoursOfOperation: [HoursOfOperations]
    var hoursOfOperationString: String {
        get{
            if(hoursOfOperation.count == 0){
                return "No times entered"
            }
            let todaysHours: HoursOfOperations = hoursOfOperation.first{$0.dayOfWeek.rawValue == Calendar.current.component(.weekday, from: Date())}!
            let df = DateFormatter()
            df.dateFormat = "HH:mma"
            return "\(df.string(from: todaysHours.startTime)) - \(df.string(from: todaysHours.endTime))"
        }
    }
    let distanceToCustomer : Double
    var distanceToCustomerString: String{
        get{
            return "\(distanceToCustomer) miles";
        }
    }
    static func ==(lhs: Merchant, rhs: Merchant) -> Bool {
        return lhs.name == rhs.name
    }
}

Merchant View:

import SwiftUI
import SwiftUIX

struct MerchantsView: View {
    @State var categories: [Category] = []
    @State var merchants: [Merchant] = []

    @ObservedObject var lm = LocationManager()

    var latitude: String  { return("\(lm.location?.latitude ?? 0)") }
    var longitude: String { return("\(lm.location?.longitude ?? 0)") }
    var placemark: String { return("\(lm.placemark?.description ?? "XXX")") }
    var status: String { return("\(lm.status)") }

    var body: some View {
        NavigationView {
            List (categories) { category in
                VStack (alignment: .leading){
                    Text(category.name)
                    ScrollView(.horizontal){
                        HStack{
                            ForEach(self.merchants, id: \.self){ merchant in
                                MerchantView(merchant: merchant, lm: self.lm)
                            }
                        }
                    }
                }
            }
            .padding(.bottom, 16)
            .onAppear{

                Api().getCategories { (categories) in
                    self.categories = categories
                }
                Api().getMerchants { (merchants) in
                    self.merchants = merchants
                }
            }
            .navigationBarTitle("Explore Merchants")
        }
    }
}

struct MerchantView: View {
    var merchant: Merchant
    let lm: LocationManager

    merchant.distanceToCustomer = 0.00

    var body: some View {
        VStack (alignment: .leading) {
            Image(self.merchant.name)
                .resizable()
                .frame(width: 200, height: 100)
                .backgroundFill(.yellow)
                .clipShape(Rectangle())
                .shadow(radius: 5)
            Text(self.merchant.name)
            Text("\(self.merchant.distanceToCustomer) | \(self.merchant.hoursOfOperationString)")
                .font(.system(size:12))
            Spacer()
        }
    }
}
Terms of Service

Privacy Policy

Cookie Policy