Reputation: 9493
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:
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)
I don't understand why this is occurring.
How can I check to see if I got data passing into the child view?
Upvotes: 0
Views: 60
Reputation: 385500
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
Upvotes: 1