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 Dictionary { | |
| public subscript(path string: Key, separator separator: String) -> Value? where Key == String { | |
| get { self[path: string.split(separator: separator).map(String.init)] } | |
| set { self[path: string.split(separator: separator).map(String.init)] = newValue } | |
| } | |
| public subscript(path path: Key...) -> Value? { | |
| get { self[path: path] } | |
| set { self[path: path] = newValue } |
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 Combine | |
| import PublishedObject // https://github.com/Amzd/PublishedObject | |
| import SwiftUI | |
| /// A property wrapper type that instantiates an observable object. | |
| @propertyWrapper | |
| public struct StateObject<ObjectType: ObservableObject>: DynamicProperty | |
| where ObjectType.ObjectWillChangePublisher == ObservableObjectPublisher { | |
| /// Wrapper that helps with initialising without actually having an ObservableObject yet |
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 Foundation | |
| extension Date { | |
| /// Returns date where **-component** is rounded to its closest | |
| /// multiple of **-amount**. Warning: month and day start at 1 | |
| /// so round(to: 6, .month) will either return month 1 or 7! | |
| func round(to amount: Int, _ component: Calendar.Component) -> Date { | |
| let cal = Calendar.current | |
| var value = cal.component(component, from: 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
| // 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 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 | |
| @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 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 Publisher { | |
| func void() -> Publishers.Map<Self, Void> { | |
| self.map { _ in () } | |
| } | |
| } |
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
| @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 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
| 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 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 | |
| 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 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 View { | |
| public func textFieldFocusableArea() -> some View { | |
| TextFieldButton { self.contentShape(Rectangle()) } | |
| } | |
| } | |
| fileprivate struct TextFieldButton<Label: View>: View { | |
| init(label: @escaping () -> Label) { | |
| self.label = label | |
| } |