0

Scenario: I want to look at a parameter of the CountryRegionListModel() in the debugger.
The following are the view and it's dependent model snippets:

enter image description here

import Combine
import UIKit

protocol URLResource {
    associatedtype DataModel: Decodable
    var url: URL? { get }
}

struct CovidResource<T: Decodable>: URLResource {
    typealias DataModel = T
    var url = URL(string: "https://disease.sh/v3/covid-19/apple/countries/Canada")
}

// =====================================================================================================

class CountryRegionListModel: ObservableObject {
    @Published var countryRegionList: [String] = []

    // Data Persistence:
    var cancellables: Set<AnyCancellable> = []

    // ---------------------------------------------------------------------------

    func getList<Resource>(urlDataModel: Resource) where Resource: URLResource {
        let remoteDataPublisher = URLSession.shared.dataTaskPublisher(for: urlDataModel.url!)
            .map(\.data)
            .receive(on: DispatchQueue.main)
            .decode(type: Resource.DataModel.self, decoder: JSONDecoder())

        remoteDataPublisher
            .sink(receiveCompletion: { completion in
                switch completion {
                case .finished:
                    print("Publisher Finished")
                case let .failure(anError):
                    Swift.print("received error: ", anError)
                }
            }, receiveValue: { [self] someValue in
                self.countryRegionList = someValue as! [String]
            }).store(in: &cancellables)
    }
}

Here I'm calling a child picker view to display the data that is injected into it.
I want to check this data: countryListViewModel.countryRegionList via the debugger:

CountryRegionPickerView(countryRegionList: $countryListViewModel.countryRegionList)
                            

enter image description here

I don't understand why this is occurring.
How can I check to see if I got data passing into the child view?

1 Answer 1

1

Since your countryListViewModel is stored in a property wrapper, there is no stored property named countryListViewModel. Instead the stored property is named _countryListViewModel. The debugger doesn't understand this (possibly because the compiler isn't explaining it properly in the debug info).

The countryListViewModel property is actually a computed property, and its getter is essentially just _countryListViewModel.wrappedValue. So try this instead:

po _countryListViewModel.wrappedValue.countryRegionList

Or (since countryRegionList is also a wrapped property) possibly this:

po _countryListViewModel.wrappedValue._countryRegionList.wrappedValue
Sign up to request clarification or add additional context in comments.

1 Comment

I've learned something here. Your first option worked; not the 2nd.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.