Skip to content

Instantly share code, notes, and snippets.

View BasThomas's full-sized avatar

Bas Broek BasThomas

View GitHub Profile
@mbrandonw
mbrandonw / lib.swift
Last active March 18, 2018 14:01
Functional setters using Swift key paths
// ----------------------------------------------------
// 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
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)
@benasher44
benasher44 / Swift42Compatibility.swift
Last active March 3, 2019 23:03
Swift 4.2 Compatibility Shims
//
// 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)
@sunshinejr
sunshinejr / Defaults.swift
Last active September 13, 2020 15:30
Using NSUserDefaults in Swift 4.
import Foundation
public let Defaults = UserDefaults.standard
open class DefaultsKeys {
fileprivate init() {}
}
open class DefaultsKey<ValueType>: DefaultsKeys {
public let _key: String
@natecook1000
natecook1000 / NSCalendar+Swift.swift
Created March 18, 2015 03:08
Swift-friendly NSCalendar methods
// 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
dhoerl / KeychainItemWrapper.h
Last active April 4, 2023 08:15
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.
/*
File: KeychainItemWrapper.h
Abstract:
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
@PurpleBooth
PurpleBooth / README-Template.md
Last active May 6, 2024 07:22
A template to make good README.md

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.

Prerequisites