-
-
Save laevandus/c34689b627c5143dc9b0801134366831 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Observing changes | |
package.recipient.publisher(for: \.postalAddress) | |
.notifyObjectWillChange(objectWillChange) | |
.store(in: &cancellables) | |
// Providing a binding for the view | |
var street: Binding<String> { | |
let package = self.package | |
return Binding<String>( | |
get: { | |
package.recipient.postalAddress.street | |
}, | |
set: { newValue in | |
let postalAddress = package.recipient.postalAddress.mutableCopy() as! CNMutablePostalAddress | |
postalAddress.street = newValue | |
package.recipient.postalAddress = postalAddress | |
} | |
) | |
} | |
extension Publisher where Self.Failure == Never { | |
public func notifyObjectWillChange(_ objectWillChange: ObservableObjectPublisher) -> AnyCancellable { | |
return self.sink { _ in | |
objectWillChange.send() | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment