【发布时间】:2020-11-02 21:20:37
【问题描述】:
场景:我想在调试器中查看CountryRegionListModel()的一个参数。
以下是视图及其依赖模型 sn-ps:
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)
}
}
在这里,我调用了一个子选择器视图来显示注入其中的数据。
我想通过调试器检查这些数据:countryListViewModel.countryRegionList:
CountryRegionPickerView(countryRegionList: $countryListViewModel.countryRegionList)
我不明白为什么会这样。
如何检查是否有数据传递到子视图?
【问题讨论】: