With Xcode 16 I'm getting this warning
Extension declares a conformance of imported type 'Date' to imported protocol 'Identifiable'; this will not behave correctly if the owners of 'Foundation' introduce this conformance in the future
for this simple extension
extension Date: Identifiable {
public var id: TimeInterval { timeIntervalSince1970 } // Warning here
}
The same warning appears for many other conformances like CustomStringConvertible
, Equatable
, Hashable
, Sendable
, etc. What should I do with those warnings?
This warning was introduced by SE-0364 and you have four options how to deal with it:
Sendable
unfortunately).struct MyDate: Identifiable {
var rawDate: Date
var id: TimeInterval { rawDate.timeIntervalSinceReferenceDate }
}
Ask the author of the module to add conformance you need (arguably the best option, but also the slowest one)
Mark this conformance with new @retroactive
attribute (acknowledging you understand the risks):
extension Date: @retroactive Identifiable {
public var id: TimeInterval { timeIntervalSince1970 }
}
This would be an error with Xcode 15 though (unless you wrap it with #if hasFeature(RetroactiveAttribute)
).
extension Foundation.Date: Swift.Identifiable {
public var id: TimeInterval { timeIntervalSince1970 }
}
Not as fancy as @retroactive
, but compatible with previous Xcode versions as is.