Skip to content

Commit df8c8db

Browse files
authored
Merge pull request #11 from polydice/feature/codable
Swift Codable
2 parents c0072c2 + ea87c64 commit df8c8db

17 files changed

+156
-110
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44

55
#### Added
66

7-
* Type safe resources generated by R.swift
87
* Syntax check with SwiftLint [#3](https://github.com/polydice/iCook-tvOS/pull/3)
98
* Code coverage
109
* A little help from [Danger](http://danger.systems/) [#4](https://github.com/polydice/iCook-tvOS/pull/4)
1110
* Protocol extended features
1211
* Swift 3 syntax updates [#5](https://github.com/polydice/iCook-tvOS/pull/5)
1312
* Simpler project quick start [#6](https://github.com/polydice/iCook-tvOS/pull/6)
13+
* Replace Freddy with Swift Codable [#11](https://github.com/polydice/iCook-tvOS/pull/11)
1414

1515
## v1.0.0
1616

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ bootstrap:
22
gem install bundler -v 2.0.2
33
bundle install
44
# pod install
5-
bundle exec pod keys set BaseAPIURL "https://polydice.com/iCook-tvOS/demo/"
5+
bundle exec pod keys set BaseAPIURL "https://cdn.jsdelivr.net/gh/polydice/iCook-tvOS@gh-pages/demo/"
66
bundle exec pod keys set CrashlyticsAPIKey "-"
77
bundle exec pod keys set TreasureDataAPIKey "-"
88
bundle exec pod install

Podfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ target :iCookTV do
1111
pod "Alamofire", "~> 4.2.0"
1212
pod "Crashlytics"
1313
pod "Fabric"
14-
pod "Freddy", "~> 3.0.0"
1514
pod "HCYoutubeParser"
1615
pod "Hue", "~> 2.0.0"
1716
pod "Kingfisher", "~> 3.2.0"

Podfile.lock

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ PODS:
33
- Crashlytics (3.8.3):
44
- Fabric (~> 1.6.3)
55
- Fabric (1.6.10)
6-
- Freddy (3.0.0)
76
- HCYoutubeParser (0.0.5)
87
- Hue (2.0.1)
98
- KeenClientTD (3.2.27)
@@ -19,7 +18,6 @@ DEPENDENCIES:
1918
- Alamofire (~> 4.2.0)
2019
- Crashlytics
2120
- Fabric
22-
- Freddy (~> 3.0.0)
2321
- HCYoutubeParser
2422
- Hue (~> 2.0.0)
2523
- Keys (from `Pods/CocoaPodsKeys`)
@@ -37,7 +35,6 @@ SPEC CHECKSUMS:
3735
Alamofire: aa2e09d871c9160ac53c90e83c68064a94e3dfbe
3836
Crashlytics: 2b6dbe138a42395577cfa73dfa1aa7248cadf39e
3937
Fabric: c73f371ee543e3f0b80608f2674750e4910d1669
40-
Freddy: 367f994c88a90dd3987293b4b1bec94a4530745a
4138
HCYoutubeParser: bc1db8c062e4b835eda381f2be2f9970f6a8d071
4239
Hue: 354caec055fdc9d38b5ef33ca2e7224721843baf
4340
KeenClientTD: ddb29a702bd4cfce5d526519ca8959d70c324c6a
@@ -48,6 +45,6 @@ SPEC CHECKSUMS:
4845
SwiftLint: a014c92b4664e8b13f380f8640a51bb1733778ba
4946
TreasureData-iOS-SDK: cc878af36b85ae3540a9a5bdb36b7bdc8707b719
5047

51-
PODFILE CHECKSUM: a39d73a29a507453d7f26041b291e321718ffeff
48+
PODFILE CHECKSUM: 3ed7b21c8acb46a6e14e06ff31e882ac9d392b95
5249

5350
COCOAPODS: 1.3.1

iCookTV.xcodeproj/project.pbxproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
B5761A581CCF5752008CCC08 /* ResourceHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5761A571CCF5752008CCC08 /* ResourceHelper.swift */; };
4646
B5761A5A1CCF6CCD008CCC08 /* VideoSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5761A591CCF6CCD008CCC08 /* VideoSpec.swift */; };
4747
B5761A5C1CCF6D78008CCC08 /* Video.json in Resources */ = {isa = PBXBuildFile; fileRef = B5761A5B1CCF6D78008CCC08 /* Video.json */; };
48+
B57C930A22FF149800BBAC40 /* KeyPathDecoding.swift in Sources */ = {isa = PBXBuildFile; fileRef = B53CD05422FEFF1C00492E27 /* KeyPathDecoding.swift */; };
4849
B586EFDB1CCA21B300EA8218 /* InsetLabel.swift in Sources */ = {isa = PBXBuildFile; fileRef = B586EFDA1CCA21B300EA8218 /* InsetLabel.swift */; };
4950
B58DE38B1CB8B54200C00266 /* CoverBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = B58DE38A1CB8B54200C00266 /* CoverBuilder.swift */; };
5051
B58E906D1D5F806600AC184D /* VideosDataSource.swift in Sources */ = {isa = PBXBuildFile; fileRef = B58E906C1D5F806600AC184D /* VideosDataSource.swift */; };
@@ -104,6 +105,7 @@
104105
B52EC3B01CB26F1B0072762C /* CGRect+Grid.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "CGRect+Grid.swift"; sourceTree = "<group>"; };
105106
B52EC3B21CB3A02E0072762C /* UIFont+TV.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIFont+TV.swift"; sourceTree = "<group>"; };
106107
B53115921CC69E7C00E75292 /* HistoryManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HistoryManager.swift; sourceTree = "<group>"; };
108+
B53CD05422FEFF1C00492E27 /* KeyPathDecoding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KeyPathDecoding.swift; sourceTree = "<group>"; };
107109
B53E39771CA1494000EB1EEE /* UIColor+TV.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIColor+TV.swift"; sourceTree = "<group>"; };
108110
B53E397A1CA14B4200EB1EEE /* CategoriesViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CategoriesViewController.swift; sourceTree = "<group>"; };
109111
B543C3E91CD1E85E008C512B /* OverlayViewPresentable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OverlayViewPresentable.swift; sourceTree = "<group>"; };
@@ -299,6 +301,7 @@
299301
B58DE38A1CB8B54200C00266 /* CoverBuilder.swift */,
300302
B543C3EE1CD1FD0B008C512B /* GroundControl.swift */,
301303
B53115921CC69E7C00E75292 /* HistoryManager.swift */,
304+
B53CD05422FEFF1C00492E27 /* KeyPathDecoding.swift */,
302305
B543C3F01CD21530008C512B /* Tracker.swift */,
303306
);
304307
path = Helpers;
@@ -530,7 +533,6 @@
530533
inputPaths = (
531534
"${SRCROOT}/Pods/Target Support Files/Pods-iCookTV/Pods-iCookTV-frameworks.sh",
532535
"${BUILT_PRODUCTS_DIR}/Alamofire/Alamofire.framework",
533-
"${BUILT_PRODUCTS_DIR}/Freddy/Freddy.framework",
534536
"${BUILT_PRODUCTS_DIR}/HCYoutubeParser/HCYoutubeParser.framework",
535537
"${BUILT_PRODUCTS_DIR}/Hue/Hue.framework",
536538
"${BUILT_PRODUCTS_DIR}/KeenClientTD/KeenClientTD.framework",
@@ -541,7 +543,6 @@
541543
name = "[CP] Embed Pods Frameworks";
542544
outputPaths = (
543545
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Alamofire.framework",
544-
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Freddy.framework",
545546
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/HCYoutubeParser.framework",
546547
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Hue.framework",
547548
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/KeenClientTD.framework",
@@ -590,7 +591,6 @@
590591
inputPaths = (
591592
"${SRCROOT}/Pods/Target Support Files/Pods-iCookTV-iCookTVTests/Pods-iCookTV-iCookTVTests-frameworks.sh",
592593
"${BUILT_PRODUCTS_DIR}/Alamofire/Alamofire.framework",
593-
"${BUILT_PRODUCTS_DIR}/Freddy/Freddy.framework",
594594
"${BUILT_PRODUCTS_DIR}/HCYoutubeParser/HCYoutubeParser.framework",
595595
"${BUILT_PRODUCTS_DIR}/Hue/Hue.framework",
596596
"${BUILT_PRODUCTS_DIR}/KeenClientTD/KeenClientTD.framework",
@@ -603,7 +603,6 @@
603603
name = "[CP] Embed Pods Frameworks";
604604
outputPaths = (
605605
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Alamofire.framework",
606-
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Freddy.framework",
607606
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/HCYoutubeParser.framework",
608607
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Hue.framework",
609608
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/KeenClientTD.framework",
@@ -661,6 +660,7 @@
661660
B50BFC071CC8AF14004F853D /* HistoryViewController.swift in Sources */,
662661
B51A95391CCF1C5100E5ED97 /* iCookTVKeys.swift in Sources */,
663662
B586EFDB1CCA21B300EA8218 /* InsetLabel.swift in Sources */,
663+
B57C930A22FF149800BBAC40 /* KeyPathDecoding.swift in Sources */,
664664
B500D9AF1CBA3B7900622198 /* LaunchViewController.swift in Sources */,
665665
B50A202B1DC4B53C00ACBF1B /* LoadingIndicatorPresentable.swift in Sources */,
666666
B500D99F1CB93D0600622198 /* MainMenuView.swift in Sources */,

iCookTV/Controllers/HistoryViewController.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ class HistoryViewController: UIViewController,
7777
isLoading = true
7878
DispatchQueue.global().async {
7979
do {
80-
let history = try HistoryManager.history.map(Video.init)
80+
let decoder = JSONDecoder()
81+
let history = try HistoryManager.history.map { try decoder.decode(Video.self, from: $0) }
8182
DispatchQueue.main.sync {
8283
self.dataSource.append(history, toCollectionView: self.collectionView)
8384
self.setOverlayViewHidden(self.dataSource.numberOfItems > 0, animated: true)

iCookTV/Controllers/LaunchViewController.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626

2727
import UIKit
2828
import Alamofire
29-
import Freddy
3029

3130
class LaunchViewController: UIViewController, DataFetching {
3231

iCookTV/Controllers/VideoPlayerController.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import UIKit
2828
import AVKit
2929
import Alamofire
30-
import Freddy
3130

3231
class VideoPlayerController: AVPlayerViewController, Trackable {
3332

@@ -90,8 +89,9 @@ class VideoPlayerController: AVPlayerViewController, Trackable {
9089
}
9190

9291
do {
93-
let json = try JSON(data: data)
94-
let video = try Video(json: json["data"] ?? nil)
92+
let decoder = JSONDecoder()
93+
let parsed = try decoder.decode(DataKeyPathDecoding<Video>.self, from: data)
94+
let video = parsed.data
9595
video.convertToPlayerItemWithCover(self?.coverImage) { [weak self] in
9696
self?.setPlayerItem($0)
9797
}

iCookTV/Controllers/VideosViewController.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626

2727
import UIKit
2828
import Alamofire
29-
import Freddy
3029
import Keys
3130

3231
class VideosViewController: UIViewController,

iCookTV/Extensions/DataRequest+Result.swift

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626

2727
import Foundation
2828
import Alamofire
29-
import Freddy
3029

3130
enum Result<T> {
3231
case success(T)
@@ -55,10 +54,10 @@ enum Result<T> {
5554

5655
extension DataRequest {
5756

58-
func responseJSONObject(
57+
func responseResult(
5958
queue: DispatchQueue? = nil,
6059
options: JSONSerialization.ReadingOptions = .allowFragments,
61-
completion: @escaping (Result<JSON>) -> Void
60+
completion: @escaping (Result<Data>) -> Void
6261
) -> Self {
6362
let serializer = DataRequest.jsonResponseSerializer(options: options)
6463

@@ -68,13 +67,7 @@ extension DataRequest {
6867
completion(.failure(error))
6968
return
7069
}
71-
72-
do {
73-
let json = try JSON(data: data)
74-
completion(.success(json))
75-
} catch {
76-
completion(.failure(error))
77-
}
70+
completion(.success(data))
7871
}
7972
}
8073

0 commit comments

Comments
 (0)