Проверка шаблона шины для iOS
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

21 lines
380B

  1. import Combine
  2. extension Cord {
  3. final class ReadOnly<T>: ObservableObject {
  4. @Published var value: T
  5. var subscriptions = [AnyCancellable]()
  6. init(
  7. _ key: String,
  8. _ defaultValue: T
  9. ) {
  10. value = defaultValue
  11. Bus.receive(
  12. [key],
  13. { [weak self] (_, v: T) in self?.value = v },
  14. sub: &subscriptions
  15. )
  16. }
  17. }
  18. }