A lightweight Swift library for hierarchical state management and change propagation in SwiftUI applications using Combine and the ObservableObject
protocol.
import CombineObservationBroadcast
class Child: ObservableObject {
@Published var count: Int = 0
func increment() {
count += 1
}
}
class Parent: ObservableObject {
private(set) lazy var child = ObservationBroadcast(Child(), to: self)
}
let parent = Parent()
var isChanged = false
let cancellable = parent.objectWillChange
.sink { isChanged = true }
parent.child().increment()
parent.child().increment()
print(parent.child().count) // Printed "2"
print(isChanged) // Printed "true"
Add the following to your Package.swift
file:
dependencies: [
.package(url: "https://github.com/inekipelov/combine-observation-broadcast.git", from: "0.3.0")
]
Or add it directly in Xcode using File → Swift Packages → Add Package Dependency...
This library is released under the MIT License. See LICENSE for details.