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

Merged
merged 9 commits into from
Jan 1, 2025
Merged

Conversation

Andrewangeta
Copy link
Contributor

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
Contributor 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

marinofelipe commented Jul 21, 2024

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 you be interested?

Copy link

codecov bot commented Jan 1, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.08%. Comparing base (3ba3a2f) to head (178cc5e).
Report is 11 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #92      +/-   ##
==========================================
- Coverage   98.09%   98.08%   -0.02%     
==========================================
  Files          22       22              
  Lines        1420     1460      +40     
==========================================
+ Hits         1393     1432      +39     
- Misses         27       28       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@marinofelipe
Copy link
Owner

Hi @Andrewangeta , I finally got the time to look into it.

I kept the same as you did, but just changed it to use a MainActor bound Task instead, and then fixed the tests with the help of swift-concurrency-extras s withSerialMainExecutor.

I think we are good to go, thanks a lot for contribution 🙇 !

cc @eliasayele

@marinofelipe marinofelipe merged commit 03d08a0 into marinofelipe:main Jan 1, 2025
3 checks passed
@marinofelipe
Copy link
Owner

This is now part of the 3.0.1 release, cheers!

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