联合收割机swift中未调用sink()
我有一门很好的LocationManager课程。这是LocationManager类的一部分联合收割机swift中未调用sink(),swift,swiftui,combine,Swift,Swiftui,Combine,我有一门很好的LocationManager课程。这是LocationManager类的一部分 var headingDegree = PassthroughSubject<Double, Never>() func locationManager(_ manager: CLLocationManager, didUpdateHeading newHeading: CLHeading) { headingDegree.send(-newHeading.magneti
var headingDegree = PassthroughSubject<Double, Never>()
func locationManager(_ manager: CLLocationManager, didUpdateHeading newHeading: CLHeading) {
headingDegree.send(-newHeading.magneticHeading)
}
我降低了我的校长学位
。这是给我带来问题的部分。如果我在update()
函数中设置断点,则永远不会调用self.degree=$0
这就是我的观点
struct CompassView: View {
@ObservedObject var viewModel: CompassViewViewModel
init(viewModel: CompassViewViewModel) {
self.viewModel = viewModel
}
var body: some View {
ZStack {
Text("aa")
.font(.footnote)
}
.onAppear {
self.viewModel.update()
}
}
}
你能告诉我为什么我的水槽没有被调用吗 我将
@State var cancelable=Set()
更改为private var cancelable=Set()
,效果很好 更新
在swiftUI1中,未调用UIHostingcontroller中的viewDidLoad
使用combine和UIKit时,在viewDidload中订阅(接收器)不起作用,而是在viewDidload中订阅
struct CompassView: View {
@ObservedObject var viewModel: CompassViewViewModel
init(viewModel: CompassViewViewModel) {
self.viewModel = viewModel
}
var body: some View {
ZStack {
Text("aa")
.font(.footnote)
}
.onAppear {
self.viewModel.update()
}
}
}