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
struct AnyEquatable: Equatable { | |
let base: Any | |
let isEqual: (_ other: AnyEquatable) -> Bool | |
init<T: Equatable>(_ base: T) { | |
self.base = base | |
self.isEqual = { base == $0.base as? T } | |
} | |
public static func ==(lhs: AnyEquatable, rhs: AnyEquatable) -> Bool { |
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
extension CGPath { | |
func apply(action: @escaping (CGPathElement)->()) { | |
var action = action | |
apply(info: &action) { | |
let action = $0!.bindMemory(to: ((CGPathElement)->()).self, capacity: 1).pointee | |
action($1.pointee) | |
} | |
} | |
} |
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
import Foundation | |
public struct WeakSet<Element>: Sequence, ExpressibleByArrayLiteral, CustomStringConvertible where Element: AnyObject { | |
private var storage = Set<Box>() | |
public init(_ members: [Element]) { | |
members.forEach { insert($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
extension CGPattern { | |
static func make(bounds: CGRect, | |
matrix: CGAffineTransform, | |
step: CGSize, | |
tiling: CGPatternTiling, | |
isColored: Bool, | |
draw: @escaping (CGContext) -> Void) -> CGPattern { | |
let drawPattern: CGPatternDrawPatternCallback = { info, ctx in |
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
import CoreGraphics | |
extension CGPath { | |
// Creates a smooth CGPath line between supplied points. | |
// | |
// Typical Polyline, straight line from point to point. | |
// | |
// /\ | |
// __ ___/ \ / |
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
import UIKit | |
public extension UIApplication { | |
// When unit testing some UIKit accessibility label properties are not updated until either; | |
// - Accessibility Inspector is connected to the specific simulator once, then closed. 🤷🏻♂️ | |
// - Calling accessibilityActivate() one time. | |
func activateSimulatorForAccessibilityTesting() { | |
accessibilityActivate() |
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
import _Concurrency | |
extension Task { | |
// Create group with n tasks, executed concurrently. | |
// Returned array preserves original order of operations. | |
static func withGroup<TaskResult>(operations: [() async throws -> TaskResult]) async throws -> [TaskResult] { | |
return try await Task.withGroup(resultType: (Int, TaskResult).self) { group in | |
for (idx, provider) in operations.enumerated() { | |
await group.add { |
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
import Combine | |
public extension Publisher { | |
/// Converts a publisher's output into the most recent output of another publisher. | |
/// | |
/// - parameter other: A publisher that will provide the latest value | |
/// - returns: A publisher that emits the latest ouput of another publisher | |
func withLatestFrom<Other: Publisher>(_ other: Other) -> WithLatestFrom<Self, Other, Other.Output> { |
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
import Combine | |
extension Publisher where Failure == Never { | |
/// Converts a publisher into a `Driver` | |
func driver() -> Driver<Output> { Driver(self) } | |
} | |
extension Driver { | |
func driver() -> Driver<Output> { self } |
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
import Combine | |
// `UIScheduler` eagerly executes actions on the current queue if | |
// it is the main thread, avoiding unnecessary async behaviour. | |
// If the current queue is not the main thread, then the action is | |
// then scheduled on the main queue asynchonously. | |
// | |
// `DispatchQueue` schedulers execute all actions asynchronously. | |
// | |
struct UIScheduler: Scheduler { |
OlderNewer