Skip to content

Instantly share code, notes, and snippets.

View kharrison's full-sized avatar
💭
Watching WWDC videos

Keith Harrison kharrison

💭
Watching WWDC videos
View GitHub Profile
@kharrison
kharrison / Protocol.swift
Created January 21, 2019 11:06
Refactoring Examples in Swift
// Example of refactoring with protocols
// Original javascript version is from Refactoring (2nd Edition) by Martin Fowler
import Foundation
struct Play {
enum Genre {
case tragedy
case comedy
}
@kharrison
kharrison / URLSession+Extension.swift
Created January 3, 2021 16:46
Using Result with URLsession
public enum NetworkingError: Error {
case unknown
case unexpectedStatus(HTTPURLResponse)
}
extension URLSession {
func load(_ url: URL,
completionHandler: @escaping (Result<Data, Error>) -> Void)
-> URLSessionDataTask {
let task = dataTask(with: url) { data, response, error in