mirror of
https://github.com/ProtonMail/ios-mail.git
synced 2026-05-15 09:50:39 +00:00
38c46c165d
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.