Skip to content

Commit

Permalink
Updated README and comments to PublishedObject
Browse files Browse the repository at this point in the history
  • Loading branch information
Amzd committed Jan 2, 2021
1 parent cf8c209 commit 027c612
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# NestedPublished
# PublishedObject

A property wrapper that forwards the objectWillChange of the wrapped ObservableObject to the enclosing ObservableObject's objectWillChange.

Expand All @@ -7,11 +7,11 @@ Just like @Published this sends willSet events to the enclosing ObservableObject

```swift
class Outer: ObservableObject {
@NestedPublished var innerNestedPublished: Inner
@PublishedObject var innerPublishedObject: Inner
@Published var innerPublished: Inner

init(_ value: Int) {
self.innerNestedPublished = Inner(value)
self.innerPublishedObject = Inner(value)
self.innerPublished = Inner(value)
}
}
Expand All @@ -27,12 +27,12 @@ class Inner: ObservableObject {
func example() {
let outer = Outer(1)

// Setting property on Outer (This will send an update with either @Published or @NestedPublished)
outer.innerNestedPublished = Inner(2) // outer.objectWillChange will be called
// 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 @NestedPublished)
outer.innerNestedPublished.value = 3 // 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
}
```
Expand Down
4 changes: 2 additions & 2 deletions Sources/PublishedObject/PublishedObject.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ public struct PublishedObject<Value: ObservableObject> where Value.ObjectWillCha
}
}

/// Force NestedPublished when using ObservableObjects
/// Force PublishedObject when using ObservableObjects
@available(iOS 13.0, OSX 10.15, tvOS 13.0, watchOS 6.0, *)
extension Published where Value: ObservableObject {
public init(wrappedValue: Value) {
fatalError("Use NestedPublished with ObservableObjects")
fatalError("Use PublishedObject with ObservableObjects")
}
}

0 comments on commit 027c612

Please sign in to comment.