Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for SwiftUI #9

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

Support for SwiftUI #9

wants to merge 5 commits into from

Conversation

slevin
Copy link
Collaborator

@slevin slevin commented Jan 2, 2023

These changes let us use BGSwift with SwiftUI.

Implementing ObservableObject in the various resources lets SwiftUI observe resource updates and update its views. I've not considered what this means for multi threading.

The BGBindingState is a way to support SwiftUI's two way bindings.

  • For things like TextField and Toggles, SwiftUI will both read and write to the same property to match its state. BG needs the writing to work as an updateWithAction.
  • Also reading and writing to the same resource means we cannot separately update the resource from some other behavior. So I create two resources which gives us full flexibility.

TODO

  • investigate multithreaded updates
  • more factory methods for BGBindingState
  • Tests
  • Example in the demo app?

I confirm that this contribution is made under the terms of the license found in the root directory of this repository's source tree and that I have the authority necessary to make this contribution on behalf of its copyright owner.

@slevin slevin added the WIP label Jan 2, 2023
Sean Levin added 3 commits January 4, 2023 10:08
* objectWillChange happens as a side effect
* observableValue gets its values changed when updating
* observableValue can support SwiftUI bindings by offering an optional
input resource which user implements independently
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant