Skip to content

Instantly share code, notes, and snippets.

View davidbjames's full-sized avatar
👨‍💻
Senior iOS Engineer at Linearity (vector/animation products)

David James davidbjames

👨‍💻
Senior iOS Engineer at Linearity (vector/animation products)
View GitHub Profile
//
// RxActivity.swift
// Uniview
//
// Created by Krunoslav Zaher on 10/18/15.
// Borrowed and revised by David James
// Original source found in the open source project RxSwift.
// Copyright © 2015 Krunoslav Zaher. All rights reserved.
//
@davidbjames
davidbjames / Matcher.swift
Last active November 3, 2017 12:17
Custom matcher and convenience functions (via Olivier H.)
/// Wrapper to perform pattern matching via closure.
/// Author: Olivier Halligon
public struct Matcher<T> {
public let closure: (T) -> Bool
public static func ~= (lhs: Matcher<T>, rhs: T) -> Bool {
return lhs.closure(rhs)
}
}
/// Perform a pattern match via closure.
@davidbjames
davidbjames / ContainmentMatcher.swift
Created October 25, 2017 16:22
Example of switch contains.
// Code via Olivier Halligon and Nate Cook
struct ContainmentMatcher<T: Hashable> {
let set: Set<T>
static func ~=(lhs: ContainmentMatcher<T>, rhs: Set<T>) -> Bool {
return rhs.isSuperset(of: lhs.set)
}
}
@davidbjames
davidbjames / ArraySetLike.swift
Last active October 15, 2017 08:55
Equatable Set-like functionality on Array.
/// Set-like functionality on Arrays Equatable elements.
/// Performance on these is O(n)
public extension Array where Element : Equatable {
func removingDuplicates() -> Array<Iterator.Element> {
var newArray = [Element]()
for element in self {
newArray.formUnion(element)
}
return newArray
@davidbjames
davidbjames / Transformable.swift
Created September 14, 2017 14:21
Transformable
public protocol Transformable : class {
func scaled(x:CGFloat, y:CGFloat, z:CGFloat?)
func rotated(_ radians:CGFloat, x:CGFloat?, y:CGFloat?, z:CGFloat?)
func translated(x:CGFloat, y:CGFloat, z:CGFloat?)
func resetScale()
func resetRotation()
func resetTranslation()
func resetAllTransforms()
}
@davidbjames
davidbjames / SaveRecordsCommand.swift
Created November 23, 2016 09:27
Saving CKRecords via RxSwift
public struct ck_SaveRecordsCommand : ObservableTask {
public typealias Element = [CKRecord]
public var records:Element
public var options:TaskOptions?
public let cloudOptions:ck_Options
private var dependency:LoginDependency?
//
// RxActivity.swift
// Uniview
//
// Created by Krunoslav Zaher on 10/18/15.
// Borrowed and revised by David James
// Original source found in the open source project RxSwift.
// Copyright © 2015 Krunoslav Zaher. All rights reserved.
//
//
// Colors.swift
// Uniview
//
// Created by David James on 10/13/16.
// Copyright © 2016 David B James. All rights reserved.
//
import UIKit
// The API
func getPeople() -> Observable<[Person]> {
return Observable.create { (observer: AnyObserver<[Person]>) -> Disposable in
self.getPeople({ (people) in
guard people != nil else {
return