Skip to content

Instantly share code, notes, and snippets.


Bas Broek BasThomas

View GitHub Profile
benasher44 / Swift42Compatibility.swift
Last active March 3, 2019 23:03
Swift 4.2 Compatibility Shims
View Swift42Compatibility.swift
// Created by Ben Asher on 6/13/18.
// Copyright © 2018-present PlanGrid. All rights reserved.
import Foundation
import MapKit
import UserNotifications
#if swift(>=4.2)
mbrandonw / lib.swift
Last active March 18, 2018 14:01
Functional setters using Swift key paths
View lib.swift
// ----------------------------------------------------
// These 3 helpers is all you need to unlock functional
// setters for every field of every immutable struct.
// ----------------------------------------------------
// A generic way to a lift writable key path and a value to a setter function.
func set<A, B>(_ kp: WritableKeyPath<A, B>, _ b: B) -> (A) -> A {
return { a in
var a = a
a[keyPath: kp] = b
sunshinejr / Defaults.swift
Last active September 13, 2020 15:30
Using NSUserDefaults in Swift 4.
View Defaults.swift
import Foundation
public let Defaults = UserDefaults.standard
open class DefaultsKeys {
fileprivate init() {}
open class DefaultsKey<ValueType>: DefaultsKeys {
public let _key: String
View Compression.swift
import Foundation
import Compression
/// A convenience class for compressing an NSData object.
/// Example:
/// ```
/// let compression = Compression(algorithm: .ZLIB)
/// let compressedData = compression.compressData(data)
/// let decompressedData = compresison.decompressData(compressedData)
PurpleBooth /
Last active March 26, 2023 03:33
A template to make good

Project Title

One Paragraph of project description goes here

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.


natecook1000 / NSCalendar+Swift.swift
Created March 18, 2015 03:08
Swift-friendly NSCalendar methods
View NSCalendar+Swift.swift
// NSCalendar+Swift.swift
// A set of Swift-idiomatic methods for NSCalendar
// (c) 2015 Nate Cook, licensed under the MIT license
extension NSCalendar {
/// Returns the hour, minute, second, and nanoseconds of a given date.
func getTimeFromDate(date: NSDate) -> (hour: Int, minute: Int, second: Int, nanosecond: Int) {
var (hour, minute, second, nanosecond) = (0, 0, 0, 0)
getHour(&hour, minute: &minute, second: &second, nanosecond: &nanosecond, fromDate: date)
dhoerl / KeychainItemWrapper.h
Last active November 24, 2022 16:33
KeychainItemWrapper ARCified. Added the ability to manage a dictionary in place of just a string - the #define PASSWORD_USES_DATA in the .m file switches the mode.
View KeychainItemWrapper.h
File: KeychainItemWrapper.h
Objective-C wrapper for accessing a single keychain item.
Version: 1.2 - ARCified
Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple
Inc. ("Apple") in consideration of your agreement to the following
terms, and your use, installation, modification or redistribution of