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
/// NavigationSplitView default a List in left view to Sidebar style, and then swipeActions modifier stop working. It's a multi level regression. The swipeActions has been broken for a while, but in macOS 12 it didn't work in .sidebar list style neither | |
NavigationSplitView { | |
List { | |
ForEach(list, id: \.self) { item in | |
HStack { | |
Text(item.title) | |
} | |
.contentShape(Rectangle()) | |
} |
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
/// This code defines an init method for the Binding type. This method accepts three parameters: | |
/// | |
/// An object of any type T | |
/// A key path to a property of type Value on that object | |
/// An optional UndoManager object | |
/// | |
/// The init method sets the Binding value to the value of the property specified by the key path. It also sets the set value of the Binding to a closure that updates the value of the property at the key path and registers an undo operation with the provided UndoManager, if one is given. | |
/// | |
/// This allows the Binding object to be used to access and update the value of the specified property on the provided object, and to register undo operations for those updates with the UndoManager. |
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
// Backport SwiftUI.Toggle.init(_:sources:isOn:) | |
// https://developer.apple.com/documentation/swiftui/toggle/init(_:ison:)-8qx3l | |
@available(iOS, deprecated: 16.0) | |
@available(macOS, deprecated: 13.0) | |
@available(tvOS, deprecated: 16.0) | |
@available(watchOS, deprecated: 9.0) | |
private extension SwiftUI.Toggle where Label == SwiftUI.Text { | |
init<C>(_ titleKey: LocalizedStringKey, sources: C, isOn: KeyPath<C.Element, Binding<Bool>>) where C : RandomAccessCollection { |
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
name: auto-format | |
on: pull_request | |
jobs: | |
format: | |
# Check if the PR is not from a fork | |
if: github.event.pull_request.head.repo.full_name == github.repository | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
with: |
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 ContentView: View { | |
@State var color: Color = .Pastel.random() | |
var body: some View { | |
Rectangle() | |
.foregroundColor(color) | |
.onTapGesture { | |
color = .Pastel.random() | |
} | |
} |
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
// Usage | |
@MainActor | |
final class AppSettings: ObservableObject { | |
static let standard = AppSettings() | |
@Published(preferenceKey: AppSettingsKey.editorHighlightSelectedLine) | |
var editorHighlightSelectedLine: Bool = true | |
} |
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 VisualEffectView: NSViewRepresentable { | |
let material: NSVisualEffectView.Material | |
let blendingMode: NSVisualEffectView.BlendingMode | |
init(material: NSVisualEffectView.Material, blendingMode: NSVisualEffectView.BlendingMode = .withinWindow) { | |
self.material = material | |
self.blendingMode = blendingMode | |
} | |
func makeNSView(context: Context) -> NSVisualEffectView { |
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 OptionSetIterator<Element: OptionSet>: IteratorProtocol where Element.RawValue == Int { | |
private let value: Element | |
init(element: Element) { | |
self.value = element | |
} | |
private lazy var remainingBits = value.rawValue | |
private var bitMask = 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
/// Wait for async operation to return value and call callback with the value | |
/// This class is intended to workaround/simplify async/await + actors isolation | |
/// https://twitter.com/krzyzanowskim/status/1523233140914876416 | |
private class AsyncWaiter<T> { | |
var didReceiveValue: Bool = false | |
let value: (T) -> Void | |
let operation: () async throws -> T | |
init(_ value: @escaping (T) -> Void, operation: @escaping () async throws -> T) { | |
self.value = value |