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 / 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
@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 / RSSFeed.swift
Last active September 1, 2021 01:59
Swift Decodable With Multiple Custom Dates
import Foundation
extension DateFormatter {
static let iso8601Full: DateFormatter = {
let formatter = DateFormatter()
formatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSZZZZZ"
formatter.calendar = Calendar(identifier: .iso8601)
formatter.timeZone = TimeZone(secondsFromGMT: 0)
formatter.locale = Locale(identifier: "en_US_POSIX")
return formatter
@kharrison
kharrison / SwiftIntegerGuide.swift
Created February 17, 2017 16:43
Swift Integer Quick Guide
// -------------------------------------
// Swift Integer Quick Guide
// -------------------------------------
// Created by Keith Harrison http://useyourloaf.com
// Copyright (c) 2017 Keith Harrison. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
@kharrison
kharrison / Country.swift
Last active February 16, 2021 15:35
Swift Hash Functions
import Foundation
struct Country {
let name: String
let capital: String
var visited: Bool
}
extension Country: Equatable {
static func == (lhs: Country, rhs: Country) -> Bool {
@kharrison
kharrison / CoreDataController.h
Last active February 26, 2021 23:11
Objective-C wrapper for NSPersistentContainer - Easy Core Data setup with iOS 10
//
// CoreDataController.h
//
// Created by Keith Harrison http://useyourloaf.com
// Copyright (c) 2016 Keith Harrison. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright
@kharrison
kharrison / CoreDataController.swift
Last active January 31, 2023 22:36
Swift wrapper for NSPersistentContainer - Easy Core Data Setup with iOS 10
//
// CoreDataController.swift
//
// Created by Keith Harrison http://useyourloaf.com
// Copyright (c) 2017 Keith Harrison. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright
@kharrison
kharrison / String.swift
Last active January 22, 2024 14:03
Swift String Playground Examples
// Swift Standard Librray - String
// Keith Harrison http://useyourloaf.com
// Import Foundation if you want to bridge to NSString
import Foundation
// ====
// Initializing a String
// ====
@kharrison
kharrison / ppc.m
Last active August 29, 2015 14:25
Popover Presentation Delegate
// Set the popover presentation controller when prepare for segue
// The presentation style is set in the storyboard
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:@"SeguePopover"])
{
self.featuredPPC = segue.destinationViewController.popoverPresentationController;
self.featuredPPC.delegate = self;
}
}

Keybase proof

I hereby claim:

  • I am kharrison on github.
  • I am kharrison (https://keybase.io/kharrison) on keybase.
  • I have a public key whose fingerprint is DA8F 843F AD53 60FB 293B 83FA A8A6 9ECD A775 E681

To claim this, I am signing this object: