@@ -860,15 +860,19 @@ extension Locale : Codable {
860
860
self . init ( identifier: identifier)
861
861
}
862
862
}
863
-
864
- public func encode( to encoder: Encoder ) throws {
863
+
864
+ // currentIsSentinel specifies whether .current should be encoded as a sentinel for compatibility with older runtimes
865
+ // When true and encoding the current locale, decoding the archive on an older runtime will decode as the new "current"
866
+ // When false and encoding the current locale, the locale is encoded as a fixed locale with preferences
867
+ // When not encoding the current locale, this parameter has no effect
868
+ internal func _encode( to encoder: Encoder , currentIsSentinel: Bool ) throws {
865
869
var container = encoder. container ( keyedBy: CodingKeys . self)
866
870
// Even if we are current/autoupdatingCurrent, encode the identifier for backward compatibility
867
871
try container. encode ( self . identifier, forKey: . identifier)
868
-
872
+
869
873
if self == Locale . autoupdatingCurrent {
870
874
try container. encode ( Current . autoupdatingCurrent, forKey: . current)
871
- } else if self == Locale . current {
875
+ } else if currentIsSentinel && self == Locale . current {
872
876
// Always encode .current for the current locale to preserve existing decoding behavior of .current when decoding on older runtimes prior to FoundationPreview 6.3 releases
873
877
try container. encode ( Current . current, forKey: . current)
874
878
} else {
@@ -880,4 +884,8 @@ extension Locale : Codable {
880
884
try container. encode ( prefs, forKey: . preferences)
881
885
}
882
886
}
887
+
888
+ public func encode( to encoder: Encoder ) throws {
889
+ try _encode ( to: encoder, currentIsSentinel: true )
890
+ }
883
891
}
0 commit comments