Files
ios-mail/Modules/InboxTesting
Mateusz Szklarek 38c46c165d Refactor: Replace nonisolated(unsafe) Calendar with @TaskLocal
The `DateEnvironment.calendar` property was previously marked with `nonisolated(unsafe)`,
which disables crucial compiler safety checks for a mutable global variable.
This pattern is unsafe and can lead to data races and unpredictable behavior in
concurrent environments.

This commit replaces `nonisolated(unsafe)` with the modern `@TaskLocal`
property wrapper available in Swift 6.1. This provides a much safer API
for managing context-specific data.

The key benefits of this change are:
- **Thread Safety:** `@TaskLocal` is inherently safe. The property is read-only by default, and modifications are confined to the specific task's scope.
- **Scoped Modifications:** Changes to the calendar are made via the `withValue` function, which guarantees that the modification only applies within a local scope and does not leak, preventing global state pollution.
- **Improved Clarity:** The API now clearly expresses its intent. Consumers must explicitly create a local scope to use a different calendar, making the code more predictable and easier to reason about.
2025-07-16 16:35:40 +02:00
..