You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+13-3Lines changed: 13 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -101,7 +101,7 @@ let any = try encoder.encode([1, 2, Int?.none, 3])
101
101
102
102
## Int Decoding Strategy
103
103
104
-
The decoding of [BinaryInteger](https://developer.apple.com/documentation/swift/binaryinteger) types (`Int`, `UInt` etc) can be adjusted via `intDecodingStrategy`.
104
+
The decoding of [`BinaryInteger`](https://developer.apple.com/documentation/swift/binaryinteger) types (`Int`, `UInt` etc) can be adjusted via `intDecodingStrategy`.
105
105
106
106
The default strategy `IntDecodingStrategy.exact` ensures the source value is exactly represented by the decoded type allowing floating point values with no fractional part to be decoded:
107
107
@@ -113,16 +113,26 @@ let values = try KeyValueDecoder().decode([Int8].self, from: [10, 20.0, -30.0, I
Values with a fractional part can also be decoded to integers by rounding with any [FloatingPointRoundingRule](https://developer.apple.com/documentation/swift/floatingpointroundingrule):
116
+
Values with a fractional part can also be decoded to integers by rounding with any [`FloatingPointRoundingRule`](https://developer.apple.com/documentation/swift/floatingpointroundingrule):
let values =try decoder.decode([Int8].self, from: [10, 20.5, 1000, -Double.infinity])
134
+
```
135
+
126
136
## UserDefaults
127
137
Encode and decode [`Codable`](https://developer.apple.com/documentation/swift/codable) types with [`UserDefaults`](https://developer.apple.com/documentation/foundation/userdefaults):
guardlet val =T(from: binaryInt, using: strategy.integers)else{
186
190
letcontext=DecodingError.Context(codingPath: codingPath, debugDescription:"\(valueDescription) at \(codingPath.makeKeyPath()), cannot be exactly represented by \(type)")
guardlet val =T(from: int64, using: strategy.integers)else{
192
196
letcontext=DecodingError.Context(codingPath: codingPath, debugDescription:"\(valueDescription) at \(codingPath.makeKeyPath()), cannot be exactly represented by \(type)")
guardlet val =T(from: double, using: strategy.integers)else{
198
202
letcontext=DecodingError.Context(codingPath: codingPath, debugDescription:"\(valueDescription) at \(codingPath.makeKeyPath()), cannot be exactly represented by \(type)")
0 commit comments