Skip to content

Commit 25888e4

Browse files
author
Itai Ferber
committed
Optionality updates to Codable API
Applies swift-corelibs-foundation changes to mirror swiftlang/swift/pull/10667.
1 parent 183cd13 commit 25888e4

File tree

2 files changed

+574
-526
lines changed

2 files changed

+574
-526
lines changed

Foundation/Codable.swift

Lines changed: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -7,64 +7,6 @@
77
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
88
//
99

10-
//===----------------------------------------------------------------------===//
11-
// Errors
12-
//===----------------------------------------------------------------------===//
13-
14-
// Adding the following extensions to EncodingError and DecodingError allows them to bridge to NSErrors implicitly.
15-
16-
fileprivate let NSCodingPathErrorKey = "NSCodingPath"
17-
fileprivate let NSDebugDescriptionErrorKey = "NSDebugDescription"
18-
19-
extension EncodingError : CustomNSError {
20-
public static var errorDomain: String = NSCocoaErrorDomain
21-
22-
public var errorCode: Int {
23-
switch self {
24-
case .invalidValue(_, _): return CocoaError.coderInvalidValue.rawValue
25-
}
26-
}
27-
28-
public var errorUserInfo: [String : Any] {
29-
let context: Context
30-
switch self {
31-
case .invalidValue(_, let c): context = c
32-
}
33-
34-
return [NSCodingPathErrorKey: context.codingPath,
35-
NSDebugDescriptionErrorKey: context.debugDescription]
36-
}
37-
}
38-
39-
extension DecodingError : CustomNSError {
40-
public static var errorDomain: String = NSCocoaErrorDomain
41-
42-
public var errorCode: Int {
43-
switch self {
44-
case .valueNotFound(_, _): fallthrough
45-
case .keyNotFound(_, _):
46-
return CocoaError.coderValueNotFound.rawValue
47-
48-
case .typeMismatch(_, _): fallthrough
49-
case .dataCorrupted(_):
50-
return CocoaError.coderReadCorrupt.rawValue
51-
}
52-
}
53-
54-
public var errorUserInfo: [String : Any] {
55-
let context: Context
56-
switch self {
57-
case .typeMismatch(_, let c): context = c
58-
case .valueNotFound(_, let c): context = c
59-
case .keyNotFound(_, let c): context = c
60-
case .dataCorrupted(let c): context = c
61-
}
62-
63-
return [NSCodingPathErrorKey: context.codingPath,
64-
NSDebugDescriptionErrorKey: context.debugDescription]
65-
}
66-
}
67-
6810
//===----------------------------------------------------------------------===//
6911
// Error Utilities
7012
//===----------------------------------------------------------------------===//

0 commit comments

Comments
 (0)