【发布时间】:2019-09-01 09:27:29
【问题描述】:
我在 ViewModel 中有一个函数,它从网络文件中获取一些数据作为 Single。在 viewModel 中,我使用 map 将其转换为不同的模型并将其返回给 ViewController。完成此映射/转换后,我想更新 ViewModel 中的 BehaviorRelay 对象,以告知其订阅者下载已完成。我无法更新此 BehaviorRelay 对象。
我尝试在函数中添加一些代码,但在 return 语句中出现错误。
var showLoading = BehaviorRelay<Bool>(value: true)
func getPropertyList(city cityID: String) -> Single<[Property]> {
return propertyListApi.getPropertyList(city: cityID).map({ [weak self] propertInfo -> [Property] in
propertInfo.map({
return Property(name: $0.name, type: "Property Type: " + $0.type, lowestPricePerNight: "", overallRatingPercentage: "Rating: " + String($0.overallRating.overall ?? 0), image: self?.getImageURL(images: $0.images))
})
})
}
我想更新 getPropertyList 函数中的 showLoading 让 ViewController 知道加载完成。
【问题讨论】: