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 SharingServicePicker: NSViewRepresentable { | |
@Binding var isPresented: Bool | |
var items: [Any] = [] | |
func makeNSView(context: Context) -> NSView { | |
let view = NSView() | |
view.translatesAutoresizingMaskIntoConstraints = false | |
return view | |
} | |
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
// 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
/// 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 |
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
import Cocoa | |
// for-in | |
func checkForIn(array: [Int], dict: [Int: String]) { | |
for num in array where dict[num] != nil { | |
num | |
} | |
} | |
checkForIn([1,2,3,4], dict: [1:"one", 2:"two"]) |
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 String { | |
func stride(by distance: String.IndexDistance, substring: (String.SubSequence) -> Void) { | |
guard distance > 0, distance < count else { | |
substring(self[...]) | |
return | |
} | |
var i = index(startIndex, offsetBy: distance, limitedBy: endIndex) ?? endIndex | |
var previ = startIndex | |
while i < endIndex { |