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
// MARK: Appending closures `a + b` | |
/// Append closures, lhs first. | |
public func + <I>(lhs: @escaping (I) -> Void, rhs: @escaping (I) -> Void) -> ((I) -> Void) { | |
return { | |
lhs($0) | |
rhs($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 SwiftUI | |
@available(iOS 14.0, *) | |
public struct ColorPickerWithoutLabel: UIViewRepresentable { | |
@Binding var selection: Color | |
var supportsAlpha: Bool = true | |
public init(selection: Binding<Color>, supportsAlpha: Bool = true) { | |
self._selection = selection | |
self.supportsAlpha = supportsAlpha |
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 { | |
func void() -> Publishers.Map<Self, Void> { | |
self.map { _ 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
@available(iOS 13.0, OSX 10.15, tvOS 13.0, watchOS 6.0, *) | |
extension AnyPublisher { | |
static var empty: Self { | |
Empty(completeImmediately: false).eraseToAnyPublisher() | |
} | |
static func constant(_ value: Output) -> Self where Failure == Never { | |
Just(value).eraseToAnyPublisher() | |
} | |
} |
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 protocol HierarchyDescription { | |
associatedtype Child: HierarchyDescription | |
var children: [Child] { get } | |
var description: String { get } | |
} | |
extension HierarchyDescription { | |
public var hierarchyDescription: String { | |
var description = self.description | |
for child in children { |
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 SwiftUI | |
extension View { | |
/// https://stackoverflow.com/a/61985678/3393964 | |
public func cursor(_ cursor: NSCursor) -> some View { | |
self.onHover { inside in | |
if inside { | |
cursor.push() | |
} else { | |
NSCursor.pop() |
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 View { | |
public func textFieldFocusableArea() -> some View { | |
TextFieldButton { self.contentShape(Rectangle()) } | |
} | |
} | |
fileprivate struct TextFieldButton<Label: View>: View { | |
init(label: @escaping () -> Label) { | |
self.label = label | |
} |
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
/// Just like @Published this sends willSet events to the enclosing ObservableObject's ObjectWillChangePublisher | |
/// but unlike @Published it also sends the wrapped value's published changes on to the enclosing ObservableObject | |
@propertyWrapper @available(iOS 13.0, *) | |
public struct NestedPublished<Value: ObservableObject> where Value.ObjectWillChangePublisher == ObservableObjectPublisher { | |
public init(wrappedValue: Value) { | |
self.wrappedValue = wrappedValue | |
self.cancellable = nil | |
startListening(to: wrappedValue) | |
} |
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 View { | |
/// Controls the application's preferred home indicator auto-hiding when this view is shown. | |
func prefersHomeIndicatorAutoHidden(_ value: Bool) -> some View { | |
preference(key: PreferenceUIHostingController.PrefersHomeIndicatorAutoHiddenPreferenceKey.self, value: value) | |
} | |
/// Controls the application's preferred screen edges deferring system gestures when this view is shown. Default is UIRectEdgeNone. | |
func edgesDeferringSystemGestures(_ edge: UIRectEdge) -> some View { | |
preference(key: PreferenceUIHostingController.PreferredScreenEdgesDeferringSystemGesturesPreferenceKey.self, value: edge) | |
} |
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 Array where Element: Identifiable { | |
public subscript(id: Element.ID) -> Element? { | |
first { $0.id == id } | |
} | |
} | |
// let arrayOfIdentifiables = [] | |
// let itemWithId = arrayOfIdentifiables[id] |