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 URLError: Error { | |
case noData, decodingError | |
} | |
extension URLSession { | |
/// A type safe URL loader that either completes with success value or error with Error | |
func jsonDecodableTask<T: Decodable>(with url: URLRequest, decoder: JSONDecoder = JSONDecoder(), completion: @escaping (Result<T, Error>) -> Void) -> URLSessionDataTask { | |
self.dataTask(with: url) { (data, response, error) in | |
DispatchQueue.main.async { |
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
// MARK: PublicKeyPinner | |
import CommonCrypto | |
import CryptoKit | |
final class PublicKeyPinner { | |
/// Stored public key hashes | |
private let hashes: [String] | |
public init(hashes: [String]) { | |
self.hashes = hashes |
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
let fromDate = Date() | |
let toDate = Date() | |
let calendar = Calendar.current | |
let components = DateComponents(hour:0 , minute: 0, second: 0) | |
guard let startDate = calendar.date(byAdding: .day, value: -1, to: from) else { | |
return | |
} | |
calendar.enumerateDates(startingAfter: startDate, matching: components, matchingPolicy: .nextTime) { date, strict, stop in |
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
protocol ViewCodeProtocol { | |
func buildViewHierarchy() | |
func buildConstraints() | |
func buildAdditionalConfiguration() | |
func build() | |
} | |
extension ViewCodeProtocol { | |
func build() { | |
self.buildViewHierarchy() |
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
class URLProtocolMock: URLProtocol { | |
/// Dictionary maps URLs to tuples of error, data, and response | |
static var mockURLs = [URL?: (error: Error?, data: Data?, response: HTTPURLResponse?)]() | |
override class func canInit(with request: URLRequest) -> Bool { | |
// Handle all types of requests | |
return true | |
} | |
override class func canonicalRequest(for request: URLRequest) -> URLRequest { |