Skip to content

inekipelov/combine-observation-broadcast

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CombineObservationBroadcast

Swift Version SPM License Swift Tests
iOS macOS tvOS watchOS

A lightweight Swift library for hierarchical state management and change propagation in SwiftUI applications using Combine and the ObservableObject protocol.

Usage

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"

Installation

Swift Package Manager

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...

License

This library is released under the MIT License. See LICENSE for details.

About

Lightweight Swift library for hierarchical state broadcasting for ObservableObjects

Topics

Resources

License

Stars

Watchers

Forks

Languages