Skip to content

Commit

Permalink
More advances here
Browse files Browse the repository at this point in the history
  • Loading branch information
piercifani committed Jun 17, 2024
1 parent e0f4992 commit 06b4930
Showing 1 changed file with 17 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,26 @@ extension EnvironmentObject {
// MARK: - API

extension EnvironmentObject.Optional {
@dynamicMemberLookup
@frozen
public struct Wrapper {
fileprivate let base: EnvironmentObject.Optional

public subscript<Subject>(dynamicMember keyPath: ReferenceWritableKeyPath<ObjectType, Subject>) -> Binding<Subject?> {
Binding<Subject?>(get: {
self.base.wrappedValue?[keyPath: keyPath]
}, set: {
if let newValue = $0 {
self.base.wrappedValue?[keyPath: keyPath] = newValue
} else {
assertionFailure("Cannot write back Optional.none to a non-Optional value.")
@MainActor
@dynamicMemberLookup
@frozen
public struct Wrapper {

fileprivate let base: EnvironmentObject.Optional

public subscript<Subject>(dynamicMember keyPath: ReferenceWritableKeyPath<ObjectType, Subject>) -> Binding<Subject?> {
Binding<Subject?>(get: {
self.base.wrappedValue?[keyPath: keyPath]
}, set: {
if let newValue = $0 {
self.base.wrappedValue?[keyPath: keyPath] = newValue
} else {
assertionFailure("Cannot write back Optional.none to a non-Optional value.")
}
})
}
})
}
}
}

// MARK: - Auxiliary
Expand Down

0 comments on commit 06b4930

Please sign in to comment.