Foundation.Date does not conform to Sendable. Now what?

363 Views Asked by At

The following presents a warning in Xcode 14 complete concurrency checking mode.

struct Article: Sendable {
    let title: String
    let date: Date // non sendable type warning
}

This warning will become an error in Swift 6.

How do we handle this?

1

There are 1 best solutions below

0
On

The sendable attribute only applies to function types, so we can convert the property to that type instead.

struct Article: Sendable {
    let title: String
    let date: @Sendable () -> Date
}