Skip to content

Commit 33582e6

Browse files
committed
Improve CodingKey description
1 parent f4e8cbb commit 33582e6

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

stdlib/public/core/Codable.swift

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public typealias Codable = Encodable & Decodable
4747
//===----------------------------------------------------------------------===//
4848

4949
/// A type that can be used as a key for encoding and decoding.
50-
public protocol CodingKey: CustomStringConvertible {
50+
public protocol CodingKey: CustomStringConvertible, CustomDebugStringConvertible {
5151
/// The string to use in a named collection (e.g. a string-keyed dictionary).
5252
var stringValue: String { get }
5353

@@ -68,8 +68,15 @@ public protocol CodingKey: CustomStringConvertible {
6868
}
6969

7070
extension CodingKey {
71+
/// A textual representation of this key.
7172
public var description: String {
72-
return stringValue
73+
let intValue = self.intValue?.description ?? "nil"
74+
return "\(String(describing: type(of: self)))(stringValue: \(stringValue), intValue: \(intValue))"
75+
}
76+
77+
/// A textual representation of this key, suitable for debugging.
78+
public var debugDescription: String {
79+
return description
7380
}
7481
}
7582

0 commit comments

Comments
 (0)