protocol CodingKey
Inheritance |
CustomDebugStringConvertible, CustomStringConvertible
View Protocol Hierarchy →
|
---|---|
Import | import Swift |
Initializers
Creates a new instance from the specified integer.
If the value passed as intValue
does not correspond to any instance of
this type, the result is nil
.
intValue
: The integer value of the desired key.
Declaration
init?(intValue: Int)
Creates a new instance from the given string.
If the string passed as stringValue
does not correspond to any instance
of this type, the result is nil
.
stringValue
: The string value of the desired key.
Declaration
init?(stringValue: String)
Instance Variables
The value to use in an integer-indexed collection (e.g. an int-keyed dictionary).
Declaration
var intValue: Int? { get }
The string to use in a named collection (e.g. a string-keyed dictionary).
Declaration
var stringValue: String { get }
A textual representation of this instance, suitable for debugging.
Calling this property directly is discouraged. Instead, convert an
instance of any type to a string by using the String(reflecting:)
initializer. This initializer works with any type, and uses the custom
debugDescription
property for types that conform to
CustomDebugStringConvertible
:
struct Point: CustomDebugStringConvertible {
let x: Int, y: Int
var debugDescription: String {
return "(\(x), \(y))"
}
}
let p = Point(x: 21, y: 30)
let s = String(reflecting: p)
print(s)
// Prints "(21, 30)"
The conversion of p
to a string in the assignment to s
uses the
Point
type's debugDescription
property.
Declaration
var debugDescription: String { get }
Declared In
CustomDebugStringConvertible
A textual representation of this instance.
Calling this property directly is discouraged. Instead, convert an
instance of any type to a string by using the String(describing:)
initializer. This initializer works with any type, and uses the custom
description
property for types that conform to
CustomStringConvertible
:
struct Point: CustomStringConvertible {
let x: Int, y: Int
var description: String {
return "(\(x), \(y))"
}
}
let p = Point(x: 21, y: 30)
let s = String(describing: p)
print(s)
// Prints "(21, 30)"
The conversion of p
to a string in the assignment to s
uses the
Point
type's description
property.
Declaration
var description: String { get }
Declared In
CustomStringConvertible
Default Implementations
A textual representation of this key, suitable for debugging.
Declaration
var debugDescription: String { get }
A textual representation of this key.
Declaration
var description: String { get }
A type that can be used as a key for encoding and decoding.