Skip to content

Instantly share code, notes, and snippets.

View josejuanqm's full-sized avatar
🐲

Jose Quintero josejuanqm

🐲
View GitHub Profile
@josejuanqm
josejuanqm / Foo.swift
Created January 17, 2024 16:50
Logical AND operator ala Javascript
protocol Delegate: AnyObject {
}
class A {
weak var delegate: Delegate?
}
class B: Delegate {
@josejuanqm
josejuanqm / Defer.swift
Created January 16, 2024 05:41
Convert any closure to async easily with `withCheckedContinuation`
func foo(_ completion: (Bool) -> Void) {
completion(Bool.random())
}
func bar() async -> Result<Bool, Never> {
return await withCheckedContinuation { continuation in
foo { result in
continuation.resume(returning: .success(result))
}
}
@josejuanqm
josejuanqm / ContentView.swift
Created January 12, 2024 06:59
Transparent background window with SwiftUI on macOS
import SwiftUI
class WindowBackedHelperView: NSView {
var didMoveToWindow: (NSWindow) -> Void
init(didMoveToWindow: @escaping (NSWindow) -> Void) {
self.didMoveToWindow = didMoveToWindow
super.init(frame: .zero)
}