Skip to content

Commit feaed8d

Browse files
committed
sty: Encodable, Decodable -> Codable
1 parent b4623f5 commit feaed8d

File tree

2 files changed

+19
-19
lines changed

2 files changed

+19
-19
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ struct TestSubscript: Equatable {
190190
```
191191

192192
```swift
193-
extension TestSubscript: Encodable, Decodable {
193+
extension TestSubscript: Codable {
194194

195195
enum Keys: CodingKey {
196196
case int, string

Sources/ExCodable/ExCodable.swift

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import Foundation
2121
/// A protocol extends `Encodable` & `Decodable` with `keyMapping`
2222
/// - seealso: [Usage](https://github.com/iwill/ExCodable#usage) from GitGub
2323
/// - seealso: `ExCodableTests.swift` form the source code
24-
public protocol ExCodable: Encodable, Decodable {
24+
public protocol ExCodable: Codable {
2525
associatedtype Root = Self where Root: ExCodable
2626
static var keyMapping: [KeyMap<Root>] { get }
2727
}
@@ -43,7 +43,7 @@ public extension ExCodable {
4343

4444
// MARK: - key-mapping
4545

46-
public struct KeyMap<Root: Encodable & Decodable> {
46+
public struct KeyMap<Root: Codable> {
4747
fileprivate let encode: (_ root: Root, _ encoder: Encoder) -> Void
4848
fileprivate let decode: ((_ root: inout Root, _ decoder: Decoder) -> Void)?
4949
fileprivate let decodeReference: ((_ root: Root, _ decoder: Decoder) -> Void)?
@@ -52,10 +52,10 @@ public struct KeyMap<Root: Encodable & Decodable> {
5252
public extension KeyMap {
5353

5454
/// Constructor for value-type with `String` type codingKeys
55-
init<Value: Encodable & Decodable>(_ keyPath: WritableKeyPath<Root, Value>,
56-
to codingKeys: String ...,
57-
encode: ((Encoder, [String], Root, WritableKeyPath<Root, Value>) -> Void)? = nil,
58-
decode: ((inout Root, WritableKeyPath<Root, Value>, Decoder, [String]) -> Void)? = nil) {
55+
init<Value: Codable>(_ keyPath: WritableKeyPath<Root, Value>,
56+
to codingKeys: String ...,
57+
encode: ((Encoder, [String], Root, WritableKeyPath<Root, Value>) -> Void)? = nil,
58+
decode: ((inout Root, WritableKeyPath<Root, Value>, Decoder, [String]) -> Void)? = nil) {
5959
self.init(encode: { (root, encoder) in
6060
if encode != nil { encode!(encoder, codingKeys, root, keyPath) }
6161
else { encoder[codingKeys.first!] = root[keyPath: keyPath] }
@@ -66,10 +66,10 @@ public extension KeyMap {
6666
}
6767

6868
/// Constructor for value-type with `CodingKey` type codingKeys
69-
init<Value: Encodable & Decodable, Key: CodingKey>(_ keyPath: WritableKeyPath<Root, Value>,
70-
to codingKeys: Key ...,
71-
encode: ((Encoder, [Key], Root, WritableKeyPath<Root, Value>) -> Void)? = nil,
72-
decode: ((inout Root, WritableKeyPath<Root, Value>, Decoder, [Key]) -> Void)? = nil) {
69+
init<Value: Codable, Key: CodingKey>(_ keyPath: WritableKeyPath<Root, Value>,
70+
to codingKeys: Key ...,
71+
encode: ((Encoder, [Key], Root, WritableKeyPath<Root, Value>) -> Void)? = nil,
72+
decode: ((inout Root, WritableKeyPath<Root, Value>, Decoder, [Key]) -> Void)? = nil) {
7373
self.init(encode: { (root, encoder) in
7474
if encode != nil { encode!(encoder, codingKeys, root, keyPath) }
7575
else { encoder[codingKeys.first!] = root[keyPath: keyPath] }
@@ -80,10 +80,10 @@ public extension KeyMap {
8080
}
8181

8282
/// Constructor for ref-type with `String` type codingKeys
83-
init<Value: Encodable & Decodable>(ref keyPath: ReferenceWritableKeyPath<Root, Value>,
84-
to codingKeys: String ...,
85-
encode: ((Encoder, [String], Root, ReferenceWritableKeyPath<Root, Value>) -> Void)? = nil,
86-
decode: ((Root, ReferenceWritableKeyPath<Root, Value>, Decoder, [String]) -> Void)? = nil) {
83+
init<Value: Codable>(ref keyPath: ReferenceWritableKeyPath<Root, Value>,
84+
to codingKeys: String ...,
85+
encode: ((Encoder, [String], Root, ReferenceWritableKeyPath<Root, Value>) -> Void)? = nil,
86+
decode: ((Root, ReferenceWritableKeyPath<Root, Value>, Decoder, [String]) -> Void)? = nil) {
8787
self.init(encode: { (root, encoder) in
8888
if encode != nil { encode!(encoder, codingKeys, root, keyPath) }
8989
else { encoder[codingKeys.first!] = root[keyPath: keyPath] }
@@ -94,10 +94,10 @@ public extension KeyMap {
9494
}
9595

9696
/// Constructor for ref-type with `CodingKey` type codingKeys
97-
init<Value: Encodable & Decodable, Key: CodingKey>(ref keyPath: ReferenceWritableKeyPath<Root, Value>,
98-
to codingKeys: Key ...,
99-
encode: ((Encoder, [Key], Root, ReferenceWritableKeyPath<Root, Value>) -> Void)? = nil,
100-
decode: ((Root, ReferenceWritableKeyPath<Root, Value>, Decoder, [Key]) -> Void)? = nil) {
97+
init<Value: Codable, Key: CodingKey>(ref keyPath: ReferenceWritableKeyPath<Root, Value>,
98+
to codingKeys: Key ...,
99+
encode: ((Encoder, [Key], Root, ReferenceWritableKeyPath<Root, Value>) -> Void)? = nil,
100+
decode: ((Root, ReferenceWritableKeyPath<Root, Value>, Decoder, [Key]) -> Void)? = nil) {
101101
self.init(encode: { (root, encoder) in
102102
if encode != nil { encode!(encoder, codingKeys, root, keyPath) }
103103
else { encoder[codingKeys.first!] = root[keyPath: keyPath] }

0 commit comments

Comments
 (0)