Let’s suppose we have this simple SwiftData model.
import Foundation
import SwiftData
@Model
final class Item {
var timestamp: Date
init(timestamp: Date) {
self.timestamp = timestamp
}
}
How to configure an EnvironmentKey
with the new @Entry
macro that uses the Item
type?
The code below triggers an error at build time:
Static property ‘defaultValue’ is not concurrency-safe because non-‘Sendable’ type ‘EnvironmentValues.__Key_someItem.Value’ (aka ‘Optional’) may have shared mutable state
import SwiftUI
import SwiftData
extension EnvironmentValues {
@Entry var someItem: Item? = nil
}
Tested with Xcode 16.0 beta (16A5171c) / Swift 6 / iOS 18.