This file contains hidden or 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
import Foundation | |
struct HeaderWidget: Decodable { | |
let title: String | |
let subtitle: String | |
} | |
struct CardWidget: Decodable { | |
let title: String | |
let image: URL |
This file contains hidden or 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
import Foundation | |
// MARK: - Throwable | |
struct Throwable<T: Decodable>: Decodable { | |
private let result: Result<T, Error> | |
init(from decoder: Decoder) throws { | |
do { | |
result = .success(try T(from: decoder)) | |
} catch let error { |
This file contains hidden or 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
{ | |
"items": [ | |
{ | |
"type": "HeaderWidget", | |
"title": "Hello world", | |
"subtitle": "Lorem ipsum" | |
}, | |
{ | |
"type": "ChartWidget", | |
"title": "Your expenses path through the month", |
This file contains hidden or 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
struct Response { | |
let items: [Widget] | |
} | |
extension Response: Decodable { | |
enum CodingKeys: CodingKey { | |
case items | |
} | |
init(from decoder: Decoder) throws { |
This file contains hidden or 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
struct Response: Decodable { | |
let items: [Widget] | |
} |
This file contains hidden or 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
enum Widget { | |
case headerWidget(HeaderWidget) | |
case cardWidget(CardWidget) | |
case buttonWidget(ButtonWidget) | |
} | |
extension Widget: Decodable { | |
enum `Type`: String, Decodable { | |
case headerWidget = "HeaderWidget" | |
case cardWidget = "CardWidget" |
This file contains hidden or 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
{ | |
"items": [ | |
{ | |
"type": "HeaderWidget", | |
"title": "Hello world", | |
"subtitle": "Lorem ipsum" | |
}, | |
{ | |
"type": "CardWidget", | |
"title": "Your top visits", |
This file contains hidden or 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
struct Throwable<T: Decodable>: Decodable { | |
private let result: Result<T, Error> | |
init(from decoder: Decoder) throws { | |
do { | |
result = .success(try T(from: decoder)) | |
} catch let error { | |
// additionally, logError(error) | |
result = .failure(error) | |
} |
This file contains hidden or 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
import UIKit | |
import XCTest | |
import SnapshotTesting | |
public protocol SnapshottableView { | |
var snapshotView: UIView { get } | |
} | |
extension UIView: SnapshottableView { | |
public var snapshotView: UIView { |
This file contains hidden or 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
// | |
// NotificationCenter+AddObserver.swift | |
// | |
// Created by Pietro Basso on 27/02/2018. | |
// | |
import Foundation | |
import UIKit | |
/** |
NewerOlder