Skip to content

Instantly share code, notes, and snippets.

@hermanbanken
Last active June 11, 2019 17:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hermanbanken/ea65fedf16ad8eac75c3dacfe6de4663 to your computer and use it in GitHub Desktop.
Save hermanbanken/ea65fedf16ad8eac75c3dacfe6de4663 to your computer and use it in GitHub Desktop.
101 SwiftUI.BindableObject with a Combine.Publisher
// 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