View tick.swift
import UIKit
import PlaygroundSupport
@objc class ViewController: UIViewController {
public func bbi(_ title: String, _ action: Selector) -> UIBarButtonItem {
return UIBarButtonItem(title: title, style: .plain, target: self, action: action)
}
var timer: Timer? = nil
var timeRemaining: Double = 0
View partition.swift
extension Collection where Iterator.Element: Comparable {
/// Returns an eagerly composed array of ordered elements
/// split at each point where a user-supplied predicate
/// evaluates to true.
///
/// ```
/// [1, 2, 2, 3, 3, 3, 1]
/// .partitioned(at: { $0 != $1.last! })
/// // [[1], [2, 2], [3, 3, 3], [1]]
///
View sleepsort.swift
import Foundation
import Dispatch
public struct SleepSort {
/// Dispatches a block after `secs` seconds
static func dispatch(after secs: Double, block: @escaping () -> Void) {
#if os(Linux)
let delay = Double(CLOCKS_PER_SEC) * secs
#else
let delay = Double(NSEC_PER_SEC) * secs
View quickash.swift
func quicksort(inout v: [Int], idxs: Range<Int>) {
if idxs.isEmpty { return }
let pivotIndex = partition(&v, idxs)
quicksort(&v, idxs.startIndex..<pivotIndex)
quicksort(&v, pivotIndex.successor()..<idxs.endIndex)
}
func quicksort(inout v: [Int]) {
quicksort(&v, indices(v))
}
View scoping.md
View willits.swift
import Cocoa
extension BinaryFloatingPoint {
public var doubleValue: Double {
guard !(self is Double) else { return self as! Double }
guard !(self is Float) else { return Double(self as! Float) }
guard !(self is Float80) else { return Double(self as! Float80) }
guard !(self is CGFloat) else { return Double(self as! CGFloat) }
fatalError("Unsupported floating point type")
}
View swill.swift
import Cocoa
public enum InterpolationCurve { case linear, easeIn, easeOut, easeInOut }
public protocol Interpolating {
func interpolateTo(value: Self, by degree: Double, curve: InterpolationCurve)
}
View block.swift
import Foundation
/// A generic Cocoa-Style completion handler
typealias CompletionHandler<T> = (T?, Error?) -> Void
/// A generic result type that returns a value or an error
enum Result<T> { case success(T), error(Error), uninitialized }
/// Provides syncronous access to results returned by
/// asynchronous processes with completion handlers
View silly.swift
//: Playground - noun: a place where people can play
import UIKit
public protocol Constructible {
init()
}
public final class MyDataSource<T: Constructible>: NSObject, UICollectionViewDataSource {
var x = T()
View miband.swift
import Cocoa
import CoreBluetooth
import PlaygroundSupport
public class BTHelper: NSObject, CBCentralManagerDelegate, CBPeripheralDelegate {
// BLE Access
var centralManager: CBCentralManager
override init() {
self.centralManager = CBCentralManager(delegate: nil, queue: nil)