This file contains hidden or 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 SwiftUI | |
import MapKit | |
struct AnyMapAnnotation: MapAnnotationProtocol { | |
let _annotationData: _MapAnnotationData | |
let base: Any | |
init<T: MapAnnotationProtocol>(_ base: T) { | |
self._annotationData = base._annotationData | |
self.base = base |
This file contains hidden or 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 SwiftUI | |
import MapKit | |
protocol MapAnnotationItem: Identifiable { | |
associatedtype Annotation: MapAnnotationProtocol | |
var coordinate: CLLocationCoordinate2D { get } | |
var annotation: Annotation { get } | |
} |
This file contains hidden or 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 SwiftUI | |
struct Dial: View { | |
@Binding public var value: Double | |
public var minValue: Double = 0 | |
public var maxValue: Double = .greatestFiniteMagnitude | |
public var divisor: Double = 1 | |
public var stepping: Double = 1 | |
@State private var dialAngle: Angle = .zero | |
@State private var dialShadowAngle: Angle = .zero |
This file contains hidden or 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
class PropertyStore<Root> { | |
private var store = [AnyHashable : Any]() | |
/// Runs the computedValue closure once and stores its result in a cache for the duration | |
/// of the property store object's lifetime. Subsequent calls to this method will return the cached value. | |
func cached<T>(_ keyPath: KeyPath<Root, T>, _ computedValue: @escaping () -> T) -> T { | |
if let storedValue = store[keyPath] as? T { | |
return storedValue | |
} | |
let value = computedValue() |
This file contains hidden or 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 | |
/// Implemented by views that can be configured with a view model | |
/// | |
/// The view model must conform to Hashable. | |
public protocol ConfigurableView: UIView { | |
associatedtype ViewModel: Hashable | |
func configure(with viewModel: ViewModel) | |
} |
This file contains hidden or 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
// MARK: - Regex extensions | |
extension String { | |
func test(for pattern: String, options: NSRegularExpression.Options = []) -> Bool { | |
guard let groups = try? matches(for: pattern, options: options) else { return false } | |
return groups.count >= 1 | |
} | |
func matches(for pattern: String, options: NSRegularExpression.Options = []) throws -> [[String]] { | |
let regex = try NSRegularExpression(pattern: pattern, options: options) |
This file contains hidden or 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 | |
/// Struct containing the arguments for the UIView.systemLayoutSizeFitting() method | |
public struct LayoutSizeFitting { | |
let targetSize: CGSize | |
let horizontalFittingPriority: UILayoutPriority | |
let verticalFittingPriority: UILayoutPriority | |
public static let `default` = LayoutSizeFitting(targetSize: UIView.layoutFittingCompressedSize, | |
horizontalFittingPriority: .fittingSizeLevel, |
This file contains hidden or 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 Array { | |
/// Returns a dictionary keyed by an arbitrary attribute of an element in the array. | |
/// | |
/// The returned dictionary can be used for look-ups by an arbitrary attribute | |
/// in an array of models with constant time complexity instead of the typical | |
/// linear complexity associated with looking up elements in an unsorted list. | |
/// | |
/// - Parameters: | |
/// - indexClosure: Callback used to specify which attribute should be used for look-ups (usually an ID) | |
func lookupTable<Index: Hashable>(indexedBy indexClosure: (Element) -> Index) -> [Index : Element] { |
This file contains hidden or 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 | |
protocol LayoutConstrainable { | |
@discardableResult func height(_ height: CGFloat, priority: UILayoutPriority) -> Self | |
@discardableResult func width(_ width: CGFloat, priority: UILayoutPriority) -> Self | |
@discardableResult func size(_ size: CGSize, priority: UILayoutPriority) -> Self | |
@discardableResult func top(to: Self, constant: CGFloat, priority: UILayoutPriority) -> Self | |
@discardableResult func leading(to: Self, constant: CGFloat, priority: UILayoutPriority) -> Self | |
@discardableResult func trailing(to: Self, constant: CGFloat, priority: UILayoutPriority) -> Self | |
@discardableResult func bottom(to: Self, constant: CGFloat, priority: UILayoutPriority) -> Self |
This file contains hidden or 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
// | |
// AgnosticSafeArea.swift | |
// | |
import UIKit | |
extension UIViewController { | |
/** | |
Auxiliary version-agnostic safe area layout guide |