Skip to content

Instantly share code, notes, and snippets.

Senior iOS Developer @ HSBC

Shaps shaps80

Senior iOS Developer @ HSBC
Block or report user

Report or block shaps80

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View PlaybackGestureRecognizer.swift
import UIKit
/// A gesture optimised for use in video playback. Both delta-offset and target-delta based translations are supported
public final class PlaybackGestureRecognizer: LongPressGestureRecognizer {
/// Specifies the direction of the scrub
public enum Direction {
/// The user is scrubbed forward through time
case forward
/// The user is scrubbed backward through time
shaps80 / URLExpander.swift
Last active Apr 16, 2019
Expands a URL by doing a HEAD request against its URL and returning the redirected URL, or the original if the URL wasn't shortened. You can call `expand(url:)` multiple times and the queue guarantees that only 1 request will be triggered at a time, in calling order.
View URLExpander.swift
import Foundation
final class URLExpander: NSObject, URLSessionTaskDelegate {
private lazy var session: URLSession = {
let config = URLSessionConfiguration.default
return URLSession(configuration: config, delegate: self, delegateQueue: queue)
private let queue: OperationQueue
shaps80 / Collection+ConsecutiveRanges.swift
Last active Jan 17, 2019
Returns an array of ranges representing the indices of consecutive elements in a collection matching a given predicate.
View Collection+ConsecutiveRanges.swift
public extension Collection where Index == Int {
func consecutiveRanges(matching predicate: (Element, Element) -> Bool) -> [ClosedRange<Index>] {
return zip(self, indices).reduce(into: [ClosedRange<Index>](), { result, tuple in
let (a, b) = tuple
let previousIndex = { result.index(before: result.endIndex) }()
if let range = result.last, isMatching(self[previousIndex], a) {
result[previousIndex] = ClosedRange(uncheckedBounds: (range.lowerBound, b))
} else {
shaps80 / DateFormatter+Docs.swift
Last active Dec 10, 2018
DateFormatter with better header docs
View DateFormatter+Docs.swift
import Foundation
public extension DateFormatter {
Makes a new DateFormatter with the specified format, calendar and locale.
Characters Example Description
View 152 Percent.xccolortheme
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "">
<plist version="1.0">
<string>1 1 1 0.997649</string>
<string>SFMono-Light - 11.0</string>
<string>1 0.827451 0 1</string>
shaps80 / ResponderController.swift
Created Nov 5, 2018
A convenient controller for working with the responder chain on iOS
View ResponderController.swift
import UIKit
/// Provides a convenient controller for working with the responder chain
public final class ResponderController: NSObject, NSCopying {
/// When true, the responder will loop through the responders when reaching the ends
public var isContinuous: Bool = true
shaps80 / Image+Color.swift
Created Sep 10, 2018
Swift Image from Color. Supports both UIImage and NSImage for cross-platform compatibility.
View Image+Color.swift
#if os(iOS)
import UIKit
public typealias PlatformImage = UIImage
public typealias PlatformColor = UIColor
import AppKit
public typealias PlatformImage = NSImage
public typealias PlatformColor = NSColor
shaps80 / 1. Transaction.swift
Last active Aug 18, 2018
A nestable transaction handler in Swift.
View 1. Transaction.swift
import Foundation
public final class Transaction {
public enum Error: Swift.Error {
case notInTransaction
private static let key = DispatchSpecificKey<Void>()
shaps80 / 1. StateMachine.swift
Last active Aug 19, 2018
A lightweight generic state machine implementation in Swift.
View 1. StateMachine.swift
import Foundation
import os.log
public protocol StateMachineDelegate: class {
associatedtype StateType: Hashable
/// Invoked before a transition is about to occur, allowing you to reject even a valid transition. Defaults to true
/// - Parameters:
shaps80 / 1. IndexPathIterator.swift
Last active Mar 28, 2019
Provides an iterator that allows for simple traversing over an dataSource's IndexPath's – including support for a header and footer per section.
View 1. IndexPathIterator.swift
public struct IndexPathIterator: IteratorProtocol {
public let indexPaths: [IndexPath]
private var index: Array<IndexPath>.Index
/// Creates a new iterator for the specified indexPaths
/// - Parameter indexPaths: The indexPaths to iterate over
public init(indexPaths: Set<IndexPath>) {
self.indexPaths = indexPaths.sorted()
You can’t perform that action at this time.