This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// like XCTAssertEqual, but handles optional unwrapping | |
public func XCTAssertEqualOptional<T: Any where T: Equatable>(expression1: @auto_closure () -> T?, expression2: @auto_closure () -> T?, _ message: String? = nil, file: String = __FILE__, line: UInt = __LINE__) { | |
if let exp1 = expression1() { | |
if let exp2 = expression2() { | |
XCTAssertEqual(exp1, exp2, message ? message! : "", file: file, line: line) | |
} else { | |
XCTFail(message ? message! : "exp1 != nil, exp2 == nil", file: file, line: line) | |
} | |
} else if let exp2 = expression2() { | |
XCTFail(message ? message! : "exp1 == nil, exp2 != nil", file: file, line: line) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// converts an array of optionals to an array of non-optionals by filtering out nil | |
public func nilter<T>(var array: Array<Optional<T>>) -> Array<T> { | |
return array.filter { $0.getLogicValue() }.map { $0! } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// A calculation that holds a left term, a right term, and an operation | |
struct Calc<T> { | |
var lt: () -> T | |
var op: (T, T) -> T | |
var rt: () -> T | |
init(lt: () -> T, op: (T, T) -> T, rt: () -> T) { | |
self.lt = lt | |
self.op = op | |
self.rt = rt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// InversionOfExecution.swift – Marc Prud'hommeaux <[email protected]> | |
/// | |
/// Demonstration of an *Inversion of Execution* (**IoE**) technique for how the same function | |
/// can be executed either synchronously with a return value or asynchronously with a | |
/// callback block depending on an optional trailing `iex` (inverted executor closure. | |
/// | |
/// • When executed without a trailing closure, the result is provided as a return value: | |
/// | |
/// `let result: Int = sum([1, 2])` | |
/// |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Demonstration of using a channel to receive and dispatch IOHIDManager events using the ChannelZ framework. | |
// | |
// Created by Marc Prud'hommeaux on 3/8/15. | |
// | |
import Cocoa | |
import IOKit | |
import ChannelZ | |
@NSApplicationMain |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public extension NSURL { | |
/// Creates a zip archive of the file/folder represented by this URL and returns a references to the zipped file | |
/// | |
/// - parameter dest: the destination URL; if nil, the destination will be this URL with ".zip" appended | |
func zip(dest: NSURL? = nil) throws -> NSURL { | |
let destURL = dest ?? self.URLByAppendingPathExtension("zip") | |
let fm = NSFileManager.defaultManager() | |
var isDir: ObjCBool = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// SHA1.swift | |
// Glib | |
// | |
// Created by Marc Prud'hommeaux on 5/1/18. | |
// Copyright © 2018 Marc Prud'hommeaux. All rights reserved. | |
// | |
// A single-file conversion of the SHA1 code from: CryptoSwift | |
// | |
// Copyright (C) 2014-2017 Marcin Krzyżanowski <[email protected]> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#if os(macOS) | |
import AppKit | |
public typealias UXImage = NSImage | |
#elseif os(iOS) | |
import UIKit | |
public typealias UXImage = UIImage | |
#endif | |
/// Extensions for system images included in SF Symbols | |
@available(macOS 10.15, iOS 13.0, *) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// A color instance that can be expressed by red, green, blue, and alpha components. | |
/// | |
/// Conformed to by: | |
/// - `CoreGraphics.CGColor` | |
/// - `CoreImage.CIColor` | |
/// - `UIKit.UIColor` | |
/// - `AppKit.NSColor` | |
/// - `SwiftUI.Color` | |
public protocol ExpressibleByColorComponents { | |
/// Create an instance of this color from the given color components. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Demonstration of how to use `anchorPreference` to mimic the floating selection | |
// behavior of `SegmentedPickerStyle`. | |
// | |
// Created by Marc Prud'hommeaux on 12/10/19. | |
// | |
import SwiftUI | |
public extension View { |