我有这个(发射了3个同时网络呼叫)
class GenerationViewModel: ObservableObject {
@Published var fetching1:Bool = false
@Published var fetching2:Bool = false
@Published var fetching3:Bool = false
func go() {
let service1 = Service(??) //what to pass here so that Service can update fetching1 only
let service2 = Service(??) //what to pass here so that Service can update fetching2 only
let service3 = Service(??) //what to pass here so that Service can update fetching3 only
}
}
如何更新另一个类中已发布的变量?
1条答案
按热度按时间lztngnrs1#
一种方法是将
self
和一个密钥路径传递给Service
,然后Service
可以使用它写入由密钥路径指定的self
的字段。我们可以这样使用它: