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 | |
/// Subscriber that weakly references its target with a closure. | |
/// The target is sent to the action when it exists, so the caller can avoid | |
/// the [weak self] dance. | |
/// | |
/// ``` | |
/// let binder = Binder(self) { $0.doSomething($1) ) | |
/// ``` | |
/// |
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 | |
/// Property wrapper that protects the wrapped value with `NSLock`. | |
/// Non trivial read/writes should access via `projectedValue` which acquires lock | |
/// and runs the supplied closure against it. | |
/// | |
/// ``` | |
/// @Locked var count: Int | |
/// $count { $0 = doSomething($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
// Closures cannot be weak, but we can wrap an object and its static factory method that returns an | |
// instance to create a pseudo weak closure | |
// | |
struct Method { | |
static func weak<T: AnyObject, A>(_ base: T, factory: @escaping (T) -> ((A) -> Void)) -> (A) -> Void { | |
{ [weak base] in base.map(factory)?($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
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 { |
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 | |
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 _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 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 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
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 |