Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/amzd/publishedobject
A property wrapper that forwards the objectWillChange of the wrapped ObservableObject to the enclosing ObservableObject's objectWillChange.
https://github.com/amzd/publishedobject
combine combine-framework property-wrapper swift-package-manager swiftui
Last synced: about 1 month ago
JSON representation
A property wrapper that forwards the objectWillChange of the wrapped ObservableObject to the enclosing ObservableObject's objectWillChange.
- Host: GitHub
- URL: https://github.com/amzd/publishedobject
- Owner: Amzd
- License: mit
- Created: 2020-07-20T09:09:56.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2024-10-05T06:15:59.000Z (3 months ago)
- Last Synced: 2024-10-28T11:52:11.642Z (about 2 months ago)
- Topics: combine, combine-framework, property-wrapper, swift-package-manager, swiftui
- Language: Swift
- Homepage:
- Size: 28.3 KB
- Stars: 31
- Watchers: 2
- Forks: 7
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# PublishedObject
A property wrapper that forwards the objectWillChange of the wrapped ObservableObject to the enclosing ObservableObject's objectWillChange.
Just like @Published this sends willSet events to the enclosing ObservableObject's ObjectWillChangePublisher but unlike @Published it also sends the wrapped value's published changes on to the enclosing ObservableObject.
```swift
class Outer: ObservableObject {
@PublishedObject var innerPublishedObject: Inner
@Published var innerPublished: Innerinit(_ value: Int) {
self.innerPublishedObject = Inner(value)
self.innerPublished = Inner(value)
}
}class Inner: ObservableObject {
@Published var value: Intinit(_ int: Int) {
self.value = int
}
}func example() {
let outer = Outer(1)
// Setting property on Outer (This will send an update with either @Published or @PublishedObject)
outer.innerPublishedObject = Inner(2) // outer.objectWillChange will be called
outer.innerPublished = Inner(2) // outer.objectWillChange will be called// Setting property on Inner (This will only send an update when using @PublishedObject)
outer.innerPublishedObject.value = 3 // outer.objectWillChange will be called !!!
outer.innerPublished.value = 3 // outer.objectWillChange will NOT be called
}
```It's only one file so you could just copy it. Also has Swift Package Manager support.