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 three options how to deal with it:
-
Don’t make such kind of extensions (rarely viable option, but option nevertheless)
-
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.
- Fully qualify the names of the type and the protocol with module names (to acknowledge the risks).
extension Foundation.Date: Swift.Identifiable {
public var id: TimeInterval { timeIntervalSince1970 }
}
Not as fancy as @retroactive
, but compatible with previous Xcode versions.