swift-composable-architecture: Main thread checks on iOS 15 - unexpected result
Describe the bug I’m currently doing some smoke testing of our app on iOS 15 using the latest Xcode beta (beta 5) in preparation for the forthcoming final release.
We’re using TCA 0.27 and it looks like the recently added main thread checks aren’t working as expected, I’m getting output like this:
Warning:
The store was interacted with on a thread that is different from the thread the store was created on:
"ViewStore.send([redacted action])" was called on the wrong thread. Make sure that "ViewStore.send" is always called on the initial thread.
Initial thread: <NSThread: 0x600000162680>{number = 29, name = main}
Current thread: <_NSMainThread: 0x6000001b40b0>{number = 1, name = main}
The "Store" class is not thread-safe, and so all interactions with an instance of "Store" (including all of its scopes and derived view stores) must be done on the same thread.
---
Caught debug breakpoint. Type "continue" ("c") to resume execution.
The weird thing here is I know that the first action sent to my store would have been on the main thread because we fire an action in application(_:didFinishLaunching)
so I don’t know how the initial thread is not the main thread (although strangely it has the name “main”).
To Reproduce If I can put together a reproducer I will uploaded it here.
Expected behavior When the first action in the app is sent on the main thread, other actions sent from the main thread should not trigger this breakpoint.
Environment
- TCA 0…27
- Xcode 13b5
- iOS 15.
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 18 (18 by maintainers)
@tgrapperon we’ve actually just converted our app over to the SwiftUI app lifecycle but we are still using
@UIApplicationDelegateAdaptor
and our old app delegate class.We do have a few analytics/crash reporting tools too that could potentially be messing with this. I’ll give Brandon’s suggestion a try, but most of the time it seems to work OK. I might add a precondition check to our
Coordinator.init
method and guard that it is initialised on the main thread.