Skip to content

Commit

Permalink
Replace Unbox with Codable; upgrade RxSwift; target macOS 10.14
Browse files Browse the repository at this point in the history
  • Loading branch information
alantai-zuhlke committed Aug 26, 2019
1 parent b46a8a3 commit c03f0a7
Show file tree
Hide file tree
Showing 17 changed files with 76 additions and 120 deletions.
24 changes: 7 additions & 17 deletions DevExcuses.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@

/* Begin PBXBuildFile section */
241F01FA0BFC50E2D06A6568 /* libPods-devexcuses-DevexcusesTest.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 7239B59036FBDC9BED38B3E8 /* libPods-devexcuses-DevexcusesTest.a */; };
6166270BC30A7670329D31CD /* libPods-DevexcusesTest.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 235CD2DE50CF5D60EEA290AF /* libPods-DevexcusesTest.a */; };
7B480B4C223254820019EB07 /* DevexcusesTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B480B4B223254820019EB07 /* DevexcusesTest.swift */; };
7B480B52223254C00019EB07 /* UnsplashClientTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B480B51223254C00019EB07 /* UnsplashClientTest.swift */; };
7B480B67223264530019EB07 /* User.swift in Sources */ = {isa = PBXBuildFile; fileRef = E71262FB2080FF78006D94DA /* User.swift */; };
7B480B68223264530019EB07 /* UserLinks.swift in Sources */ = {isa = PBXBuildFile; fileRef = E71262FD20810014006D94DA /* UserLinks.swift */; };
Expand All @@ -33,16 +31,13 @@
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
235CD2DE50CF5D60EEA290AF /* libPods-DevexcusesTest.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-DevexcusesTest.a"; sourceTree = BUILT_PRODUCTS_DIR; };
27C93E4E9697D42766097BFE /* Pods-devexcuses.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-devexcuses.release.xcconfig"; path = "Pods/Target Support Files/Pods-devexcuses/Pods-devexcuses.release.xcconfig"; sourceTree = "<group>"; };
3E863DF3A0B23534EF450EF5 /* Pods-DevexcusesTest.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-DevexcusesTest.release.xcconfig"; path = "Pods/Target Support Files/Pods-DevexcusesTest/Pods-DevexcusesTest.release.xcconfig"; sourceTree = "<group>"; };
539D1BC2C6EE6F55F52398E0 /* Pods-devexcuses-DevexcusesTest.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-devexcuses-DevexcusesTest.release.xcconfig"; path = "Pods/Target Support Files/Pods-devexcuses-DevexcusesTest/Pods-devexcuses-DevexcusesTest.release.xcconfig"; sourceTree = "<group>"; };
7239B59036FBDC9BED38B3E8 /* libPods-devexcuses-DevexcusesTest.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-devexcuses-DevexcusesTest.a"; sourceTree = BUILT_PRODUCTS_DIR; };
7B480B49223254820019EB07 /* DevexcusesTest.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = DevexcusesTest.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
7B480B4B223254820019EB07 /* DevexcusesTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DevexcusesTest.swift; sourceTree = "<group>"; };
7B480B4D223254820019EB07 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
7B480B51223254C00019EB07 /* UnsplashClientTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UnsplashClientTest.swift; sourceTree = "<group>"; };
A2680B78518C1AF55F934501 /* libPods-devexcusestest.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-devexcusestest.a"; sourceTree = BUILT_PRODUCTS_DIR; };
A58DB4D36B5F52A24E6ED461 /* Pods-devexcuses.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-devexcuses.debug.xcconfig"; path = "Pods/Target Support Files/Pods-devexcuses/Pods-devexcuses.debug.xcconfig"; sourceTree = "<group>"; };
ADAB50A2F0A56B20D37C93A0 /* libPods-devexcuses.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-devexcuses.a"; sourceTree = BUILT_PRODUCTS_DIR; };
E70963302081BDD8006B381C /* Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Extensions.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -70,7 +65,6 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
6166270BC30A7670329D31CD /* libPods-DevexcusesTest.a in Frameworks */,
241F01FA0BFC50E2D06A6568 /* libPods-devexcuses-DevexcusesTest.a in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -99,14 +93,13 @@
name = Pods;
sourceTree = "<group>";
};
7B480B4A223254820019EB07 /* DevexcusesTest */ = {
7B480B4A223254820019EB07 /* DevExcusesTest */ = {
isa = PBXGroup;
children = (
7B480B51223254C00019EB07 /* UnsplashClientTest.swift */,
7B480B4B223254820019EB07 /* DevexcusesTest.swift */,
7B480B4D223254820019EB07 /* Info.plist */,
);
path = DevexcusesTest;
path = DevExcusesTest;
sourceTree = "<group>";
};
E71262FA2080FF59006D94DA /* Models */ = {
Expand Down Expand Up @@ -150,7 +143,7 @@
E77A61982081F06800F8E1B7 /* README.md */,
E75B4B15209CA74500A44D10 /* Podfile */,
E7CDCC6E2080F42200A553DF /* DevExcuses */,
7B480B4A223254820019EB07 /* DevexcusesTest */,
7B480B4A223254820019EB07 /* DevExcusesTest */,
E7CDCC6D2080F42200A553DF /* Products */,
42F8B77797667FD49945E145 /* Pods */,
F7C37CE0587B069290983FA6 /* Frameworks */,
Expand Down Expand Up @@ -179,8 +172,6 @@
isa = PBXGroup;
children = (
ADAB50A2F0A56B20D37C93A0 /* libPods-devexcuses.a */,
A2680B78518C1AF55F934501 /* libPods-devexcusestest.a */,
235CD2DE50CF5D60EEA290AF /* libPods-DevexcusesTest.a */,
7239B59036FBDC9BED38B3E8 /* libPods-devexcuses-DevexcusesTest.a */,
);
name = Frameworks;
Expand Down Expand Up @@ -361,7 +352,6 @@
7B480B69223264530019EB07 /* PhotoUrls.swift in Sources */,
7B480B6C2232645E0019EB07 /* Extensions.swift in Sources */,
7B480B52223254C00019EB07 /* UnsplashClientTest.swift in Sources */,
7B480B4C223254820019EB07 /* DevexcusesTest.swift in Sources */,
7B480B68223264530019EB07 /* UserLinks.swift in Sources */,
7B480B67223264530019EB07 /* User.swift in Sources */,
);
Expand Down Expand Up @@ -482,7 +472,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 10.10;
MACOSX_DEPLOYMENT_TARGET = 10.14;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = macosx;
Expand Down Expand Up @@ -535,7 +525,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 10.10;
MACOSX_DEPLOYMENT_TARGET = 10.14;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = macosx;
SWIFT_COMPILATION_MODE = wholemodule;
Expand All @@ -558,7 +548,7 @@
"@executable_path/../Frameworks",
"@loader_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 10.10;
MACOSX_DEPLOYMENT_TARGET = 10.14;
PRODUCT_BUNDLE_IDENTIFIER = com.github.ayltai.devexcuses;
PRODUCT_NAME = "Developers Excuses";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
Expand All @@ -582,7 +572,7 @@
"@executable_path/../Frameworks",
"@loader_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 10.10;
MACOSX_DEPLOYMENT_TARGET = 10.14;
PRODUCT_BUNDLE_IDENTIFIER = com.github.ayltai.devexcuses;
PRODUCT_NAME = "Developers Excuses";
SWIFT_VERSION = 4.0;
Expand Down
12 changes: 6 additions & 6 deletions DevExcuses/Sources/DevExcusesView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,9 @@ class DevExcusesView: ScreenSaverView {
.subscribe { event in
if let error = event.error {
self.update(
excuse: error.localizedDescription,
excuse : error.localizedDescription,
background: nil,
userName: nil,
userName : nil,
profileUrl: nil
)

Expand All @@ -219,9 +219,9 @@ class DevExcusesView: ScreenSaverView {
.subscribe { event in
if let error = event.error {
self.update(
excuse: error.localizedDescription,
excuse : error.localizedDescription,
background: nil,
userName: nil,
userName : nil,
profileUrl: nil
)
} else if
Expand All @@ -231,9 +231,9 @@ class DevExcusesView: ScreenSaverView {
let links = user.links,
let profileUrl = links.html {
self.update(
excuse: DevExcusesView.excuses[DevExcusesView.excuses.count.random()],
excuse : DevExcusesView.excuses[DevExcusesView.excuses.count.random()],
background: data,
userName: userName,
userName : userName,
profileUrl: profileUrl)
}

Expand Down
6 changes: 3 additions & 3 deletions DevExcuses/Sources/KenBurnsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ final class KenBurnsView: NSImageView {
private var duration: TimeInterval = 15

func animate(image: NSImage?, alpha: CGFloat, duration: TimeInterval) {
self.image = image
self.alphaValue = alpha
self.duration = duration
self.image = image
self.alphaValue = alpha
self.duration = duration
}

override var wantsUpdateLayer: Bool {
Expand Down
15 changes: 10 additions & 5 deletions DevExcuses/Sources/Models/Photo.swift
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import Unbox
struct Photo: Codable {
enum CodingKeys: CodingKey {
case user
case urls
}

struct Photo: Unboxable {
let user: User?
let urls: PhotoUrls?

init(unboxer: Unboxer) throws {
self.user = unboxer.unbox(key: "user")
self.urls = unboxer.unbox(key: "urls")
init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)

self.user = try container.decodeIfPresent(User.self, forKey: .user)
self.urls = try container.decodeIfPresent(PhotoUrls.self, forKey: .urls)
}
}
12 changes: 8 additions & 4 deletions DevExcuses/Sources/Models/PhotoUrls.swift
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import Unbox
struct PhotoUrls: Codable {
enum CodingKeys: CodingKey {
case custom
}

struct PhotoUrls: Unboxable {
let custom: String?

init(unboxer: Unboxer) throws {
self.custom = unboxer.unbox(key: "custom")
init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)

self.custom = try container.decodeIfPresent(String.self, forKey: .custom)
}
}
15 changes: 10 additions & 5 deletions DevExcuses/Sources/Models/User.swift
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import Unbox
struct User: Codable {
enum CodingKeys: CodingKey {
case name
case links
}

struct User: Unboxable {
let name : String?
let links: UserLinks?

init(unboxer: Unboxer) throws {
self.name = unboxer.unbox(key: "name")
self.links = unboxer.unbox(key: "links")
init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)

self.name = try container.decodeIfPresent(String.self, forKey: .name)
self.links = try container.decodeIfPresent(UserLinks.self, forKey: .links)
}
}
12 changes: 8 additions & 4 deletions DevExcuses/Sources/Models/UserLinks.swift
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import Unbox
struct UserLinks: Codable {
enum CodingKeys: CodingKey {
case html
}

struct UserLinks: Unboxable {
let html: String?

init(unboxer: Unboxer) throws {
self.html = unboxer.unbox(key: "html")
init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)

self.html = try container.decodeIfPresent(String.self, forKey: .html)
}
}
5 changes: 2 additions & 3 deletions DevExcuses/Sources/UnsplashClient.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import RxSwift
import Unbox

final class UnsplashClient {
private static let endPoint = "https://api.unsplash.com/"
Expand All @@ -26,15 +25,15 @@ final class UnsplashClient {
mutable.path = "/photos/random"
mutable.queryItems = queryItems

URLSession(configuration: URLSessionConfiguration.default).dataTask(with: mutable.url!) { (data, response, error) in
URLSession.shared.dataTask(with: mutable.url!) { (data, response, error) in
if let error = error {
observer.onError(error as NSError)
} else if
let response = response as? HTTPURLResponse,
let data = data {
if response.isSuccess {
do {
let photo: Photo = try unbox(data: data)
let photo: Photo = try JSONDecoder().decode(Photo.self, from: data)
observer.onNext(photo)
} catch let error as NSError {
observer.onError(error)
Expand Down
File renamed without changes.
33 changes: 0 additions & 33 deletions DevexcusesTest/DevexcusesTest.swift

This file was deleted.

20 changes: 3 additions & 17 deletions DevexcusesTest/UnsplashClientTest.swift
Original file line number Diff line number Diff line change
@@ -1,34 +1,20 @@
//
// UnsplashClientTest.swift
// DevexcusesTest
//
// Created by Brian Chung on 8/3/2019.
// Copyright © 2019 Alan Tai. All rights reserved.
//

import XCTest
import Nimble

class UnsplashClientTest: XCTestCase {

private var unsplashClient: UnsplashClient!
private let apiKey = "Please replace your key here"

override func setUp() {
// Put setup code here. This method is called before the invocation of each test method in the class.
unsplashClient = UnsplashClient(apiKey: apiKey)
}

override func tearDown() {
// Put teardown code here. This method is called after the invocation of each test method in the class.
unsplashClient = UnsplashClient(apiKey: "Please replace your key here")
}

func testRandom() {
let targetSize = CGSize(width: 800, height: 600)

for _ in 0...2 {
waitUntil(timeout: 10.0) { done in
_ = self.unsplashClient.random(size: targetSize, query: nil)
.subscribe(onNext: { (photo) in
.subscribe(onNext: { photo in
done()
})
}
Expand Down
5 changes: 2 additions & 3 deletions Podfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
platform :osx, '10.10'
platform :osx, '10.14'

target 'devexcuses' do
pod 'RxSwift', '~> 4.0'
pod 'Unbox', '~> 3.0'
pod 'RxSwift'
pod 'SwiftLint'

target 'DevexcusesTest' do
Expand Down
24 changes: 10 additions & 14 deletions Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,32 +1,28 @@
PODS:
- Nimble (7.3.4)
- Quick (1.3.4)
- RxSwift (4.3.1)
- SwiftLint (0.25.1)
- Unbox (3.0.0)
- Nimble (8.0.2)
- Quick (2.1.0)
- RxSwift (5.0.0)
- SwiftLint (0.34.0)

DEPENDENCIES:
- Nimble
- Quick
- RxSwift (~> 4.0)
- RxSwift
- SwiftLint
- Unbox (~> 3.0)

SPEC REPOS:
https://github.com/cocoapods/specs.git:
- Nimble
- Quick
- RxSwift
- SwiftLint
- Unbox

SPEC CHECKSUMS:
Nimble: 051e3d8912d40138fa5591c78594f95fb172af37
Quick: f4f7f063c524394c73ed93ac70983c609805d481
RxSwift: fe0fd770a43acdb7d0a53da411c9b892e69bb6e4
SwiftLint: ce933681be10c3266e82576dad676fa815a602e9
Unbox: 9ed33b2a31f7a8a049f54b94d40c4a52a28c4d9d
Nimble: 622629381bda1dd5678162f21f1368cec7cbba60
Quick: 4be43f6634acfa727dd106bdf3929ce125ffa79d
RxSwift: 8b0671caa829a763bbce7271095859121cbd895f
SwiftLint: 79d48a17c6565dc286c37efb8322c7b450f95c67

PODFILE CHECKSUM: 445cfd34da02ee18ec26b2b018630aa0b784a60d
PODFILE CHECKSUM: c4e102af2eb5609201f4523b659b339ea988fe7c

COCOAPODS: 1.5.3
Loading

0 comments on commit c03f0a7

Please sign in to comment.