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

Fix SwiftUI warnings. #92

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Andrewangeta
Copy link

Why?

Writing to the underlying wrappedValue of a property wrapper wasn't guaranteed to be on the main thread depending on how a user might be using it.

Changes

This makes that guarantee by wrapping those write operations in a DispatchQueue

Tests

Verified on a real device using iOS 16.2 and Xcode 14.2

Issue 91

@marinofelipe
Copy link
Owner

Thanks @Andrewangeta 🙇 .

The tests are failing and I expect it's because of the async dispatch introduced, since the tests were before expecting the wrappers to be synchronously updated.

I think there a few ways we could get around that:

  • Introduce some sort of abstraction for DispatchQueue which could be then injected into WrappedTextField, default to DispatchQueue.main and where a mock/fake can be injected during tests
  • Introduce https://github.com/pointfreeco/combine-schedulers and use it instead to make the code run synchronously on tests

I'd personally prefer those over async expectations in order to have tests more deterministic and faster.

Let me know what you think.
I'm not sure if I can commit to your branch, so let me know if you'd like to give me edit permissions, or if you'd like to try it yourself.

@marinofelipe
Copy link
Owner

When running on Xcode 14.2 I also faced a similar warning in WrappedTextField:122, which we could also take the opportunity to fix :)

@marinofelipe
Copy link
Owner

Or perhaps will be easier to go with the async await path and make use of MainActors where needed.

@Andrewangeta
Copy link
Author

@marinofelipe Yea I think actors would be a fair approach and to use async await as well.

@eliasayele
Copy link

Does anyone working on it? because it's useful feature.

@marinofelipe
Copy link
Owner

Does anyone working on it? because it's useful feature.

Hi @eliasayele . For sure, as far as I know no one is looking it, would be interested?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants