Last active
June 11, 2019 17:22
-
-
Save hermanbanken/ea65fedf16ad8eac75c3dacfe6de4663 to your computer and use it in GitHub Desktop.
101 SwiftUI.BindableObject with a Combine.Publisher
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
// This is the bare-minimum you need to know to create a SwiftUI.BindableObject with a Combine.Publisher | |
final class MyUserData: BindableObject { | |
// this ==vvvvvvv must be a `Publisher` type | |
let didChange = PassthroughSubject<MyUserData, Never>() | |
var myProperty = false { | |
didSet { | |
// this ==vvvvvvv | |
didChange.send(self) | |
} | |
} | |
} | |
// ..... | |
struct MyView: View { | |
@EnvironmentObject var userData: MyUserData | |
var body: some View { ... } | |
} | |
// ..... | |
MyView() | |
.environmentObject(MyUserData()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment