Skip to content

Commit

Permalink
Rename to PublishedObject and added tvOS/macOS/watchOS support
Browse files Browse the repository at this point in the history
  • Loading branch information
Amzd committed Jan 2, 2021
1 parent 0e93cee commit cf8c209
Showing 1 changed file with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import Combine

/// 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
@propertyWrapper @available(iOS 13.0, *)
public struct NestedPublished<Value: ObservableObject> where Value.ObjectWillChangePublisher == ObservableObjectPublisher {
@propertyWrapper @available(iOS 13.0, OSX 10.15, tvOS 13.0, watchOS 6.0, *)
public struct PublishedObject<Value: ObservableObject> where Value.ObjectWillChangePublisher == ObservableObjectPublisher {

public init(wrappedValue: Value) {
self.wrappedValue = wrappedValue
Expand All @@ -19,7 +19,7 @@ public struct NestedPublished<Value: ObservableObject> where Value.ObjectWillCha
public static subscript<EnclosingSelf: ObservableObject>(
_enclosingInstance observed: EnclosingSelf,
wrapped wrappedKeyPath: ReferenceWritableKeyPath<EnclosingSelf, Value>,
storage storageKeyPath: ReferenceWritableKeyPath<EnclosingSelf, NestedPublished>
storage storageKeyPath: ReferenceWritableKeyPath<EnclosingSelf, PublishedObject>
) -> Value where EnclosingSelf.ObjectWillChangePublisher == ObservableObjectPublisher {
get {
observed[keyPath: storageKeyPath].setParent(observed)
Expand Down Expand Up @@ -53,7 +53,7 @@ public struct NestedPublished<Value: ObservableObject> where Value.ObjectWillCha
}

/// Force NestedPublished when using ObservableObjects
@available(iOS 13.0, *)
@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")
Expand Down

0 comments on commit cf8c209

Please sign in to comment.