-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
107 changed files
with
8,334 additions
and
11,524 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// | ||
// AlamoRecordDecoder.swift | ||
// AlamoRecord | ||
// | ||
// Created by Dalton Hinterscher on 6/6/19. | ||
// | ||
|
||
import Alamofire | ||
|
||
class AlamoRecordDecoder: DataDecoder { | ||
|
||
private let keyPath: String? | ||
|
||
init(keyPath: String?) { | ||
self.keyPath = keyPath | ||
} | ||
|
||
func decode<D>(_ type: D.Type, from data: Data) throws -> D where D : Decodable { | ||
let decoder = JSONDecoder() | ||
guard let keyPath = keyPath, | ||
let json = try JSONSerialization.jsonObject(with: data, options: .mutableContainers) as? [String: Any], | ||
let keyPathJson = json[keyPath] else { | ||
return try decoder.decode(D.self, from: data) | ||
} | ||
let keyPathJsonData = try JSONSerialization.data(withJSONObject: keyPathJson, options: .prettyPrinted) | ||
return try decoder.decode(D.self, from: keyPathJsonData) | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.