📜  绑定对象 - Swift 代码示例

📅  最后修改于: 2022-03-11 15:00:59.629000             🧑  作者: Mango

代码示例1
import SwiftUI
import Combine

final class SliderData: BindableObject {

  let didChange = PassthroughSubject()

  var sliderValue: Float = 0 {
    willSet {
      print(newValue)
      didChange.send(self)
    }
  }
}

struct ContentView : View {

  @EnvironmentObject var sliderData: SliderData

  var body: some View {
    Slider(value: $sliderData.sliderValue)
  }
}