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 AttributesOf<Object>: CustomStringConvertible { | |
enum Error: Swift.Error { case message(String) } | |
public typealias Assignment = (keyPath: AnyKeyPath, set: (Object) -> Void) | |
private(set) var assignments: [Assignment] | |
init(@AttributesOfBuilder<Object> _ builder: () throws -> [Assignment]) rethrows { | |
assignments = try builder() |
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 struct DeepMapOptions: OptionSet { | |
public let rawValue: UInt | |
public init(rawValue: UInt) { self.rawValue = rawValue } | |
public static let mappingOverArrays = DeepMapOptions(rawValue: 1 << 0) | |
public static let all: DeepMapOptions = [.mappingOverArrays] | |
} | |
extension Dictionary where Value == Any { |
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 Optional { | |
public func or(throw error: @autoclosure () -> Error) throws -> Wrapped { | |
guard let wrapped = self else { throw error() } | |
return wrapped | |
} | |
} | |
extension String { | |
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 Darwin | |
import Foundation | |
import UIKit | |
// https://github.com/xybp888/iOS-SDKs/blob/master/iPhoneOS17.1.sdk/System/Library/PrivateFrameworks/CoreSVG.framework/CoreSVG.tbd | |
// https://developer.limneos.net/index.php?ios=17.1&framework=UIKitCore.framework&header=UIImage.h | |
@objc | |
class CGSVGDocument: NSObject { } |
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 Publisher where Failure == Never { | |
public func sink<Root>(to handler: @escaping (Root) -> (Output) -> Void, on root: Root) -> AnyCancellable where Root: AnyObject { | |
sink{ [weak root] value in | |
guard let root = root else { return } | |
handler(root)(value) | |
} | |
} | |
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 UIView { | |
func publisher<G>(for gestureRecognizer: G) -> UIGestureRecognizer.Publisher<G> where G: UIGestureRecognizer { | |
UIGestureRecognizer.Publisher(gestureRecognizer: gestureRecognizer, view: self) | |
} | |
} | |
extension UIGestureRecognizer { | |
struct Publisher<G>: Combine.Publisher where G: UIGestureRecognizer { |
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 JSON { | |
enum Index { | |
case ordinal(Int), key(String) | |
} | |
private(set) var any: Any? | |
init(_ any: Any? = nil) { | |
self.any = any |
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 Dictionary { | |
public typealias KeyValuePairs = [KeyValuePair<Key, Value>] | |
public var keyValuePairs: KeyValuePairs { map(KeyValuePair.init) } | |
} | |
extension Collection where Element: KeyValuePair_P { | |
public var dictionary: [Element.Key: Element.Value] { Dictionary(uniqueKeysWithValues: map(\.tuple)) } | |
} | |
public protocol KeyValuePair_P { |
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
protocol AnyDictionary: Collection { | |
associatedtype Key: Hashable | |
associatedtype Keys | |
associatedtype Value | |
associatedtype Values | |
associatedtype Index | |
var keys: Keys { get } | |
var values: Values { get } |
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 | |
class AtomicCollection<C> where C: Collection { | |
var base: C | |
let queue: DispatchQueue | |
init(_ base: C, label: String, qos: DispatchQoS = .unspecified, autoreleaseFrequency: DispatchQueue.AutoreleaseFrequency = .inherit, target: DispatchQueue? = nil) { | |
self.base = base | |
self.queue = DispatchQueue( |