Skip to content

Instantly share code, notes, and snippets.

View lukaskubanek's full-sized avatar

Lukas Kubanek lukaskubanek

View GitHub Profile
@tyirvine
tyirvine / InactiveWindowTapHelper.swift
Created June 14, 2021 21:02
This registers clicks on a view in SwiftUI even when the window is not key or main
//
// InactiveWindowTapHelper.swift
//
// Created by Ty Irvine on 2021-06-14.
//
// This registers clicks on a view in SwiftUI even when the window is not key or main.
//
// Usage ⤵︎
/*
@simonbs
simonbs / childForStatusBarStyle.swift
Last active September 25, 2023 14:49
It seems that -childForStatusBarStyle: isn’t called on a UIViewController that is presented from a SwiftUI view using UIViewControllerRepresentable. Or am I doing something wrong? I came up with this *ugly* workaround that swizzles -childForStatusBarStyle: to return an associated object when present and uses the default implementation as fallback.
// We'll store a UIViewController as an associated object and don't want to store a strong reference to it.
private final class WeakBoxedValue<T: AnyObject>: NSObject {
private(set) weak var value: T?
init(_ value: T?) {
self.value = value
}
}
// Use associated objects to a UIViewController that should determine the status bar appearance.
@hishnash
hishnash / ExampleWindowReaderApp.swift
Created December 21, 2020 05:59
Access to the underlying UIWindow & NSWindow in swiftUI gives access to window methods and attributes.
//
// ExampleWindowReaderApp.swift
// Shared
//
// Created by Matthaus Woolard on 21/12/2020.
//
import SwiftUI
@main
@krzyzanowskim
krzyzanowskim / myview.swift
Last active October 24, 2020 10:16
FB8820682: Since when NSView.setNeedsDisplayInRect does not affects drawRect rectangle
// macOS 11.0 (20A5395g)
// Xcode 12.2 beta 3 (12B5035g)
class MyView: NSView {
override init(frame frameRect: NSRect) {
super.init(frame: frameRect)
DispatchQueue.main.asyncAfter(deadline: .now() + .seconds(1)) {
let rect = NSRect(x: 10, y: 10, width: 10, height: 10)
extension UIHostingController {
convenience public init(rootView: Content, ignoreSafeArea: Bool) {
self.init(rootView: rootView)
if ignoreSafeArea {
disableSafeArea()
}
}
func disableSafeArea() {
@frankschlegel
frankschlegel / Combine+SelfBindings.swift
Last active February 17, 2024 02:14
Convenience extensions for Combine adding memory-save bindings and Cancellable management
import Combine
/// Classes implementing this protocol can be target of convenience Publisher
/// bindings and assignments without causing accidental retain cycles.
/// Those bindings and assignments are also released together with the target.
///
/// For example:
///
/// aPublisher.bind(to: self) { me, object in
@ole
ole / !swiftui-reflection-dump.md
Last active November 30, 2025 22:27
A dump of the SwiftUI.framework binary for the iOS simulator (as of Xcode 12.0 beta 2) using the swift-reflection-dump tool.

A dump of the SwiftUI.framework binary for the iOS simulator (as of Xcode 12.0 beta 2) using the swift-reflection-dump tool.

Note: I used a Swift 5.3 compiler build from a few weeks ago that I had laying around. Because of ABI stability, I don't think the swift-reflection-dump version has to match the compiler version that was used to build the binary, but I'm not 100% sure.

@mluisbrown
mluisbrown / Rx2Ras-Cheatsheet.md
Last active May 19, 2024 10:47
An RxSwift to ReactiveSwift cheatsheet
// Run any SwiftUI view as a Mac app.
import Cocoa
import SwiftUI
NSApplication.shared.run {
VStack {
Text("Hello, World")
.padding()
.background(Capsule().fill(Color.blue))
@IsaacXen
IsaacXen / README.md
Last active July 18, 2026 12:57
(Almost) Every WWDC videos download links for aria2c.