Skip to content

Instantly share code, notes, and snippets.

View lukaskubanek's full-sized avatar

Lukas Kubanek lukaskubanek

View GitHub Profile
import SwiftUI
extension View {
/// A custom popover modifier that ensures the system automatically selects the best
/// orientation for the popover's arrow, compatible with both iOS 17 and 18.
///
/// On iOS 17, the `arrowEdge` is treated as a hint and may be ignored if the popover does
/// not fit. On iOS 18, the `arrowEdge` is strictly enforced, potentially causing layout
/// issues if the content doesn't fit.
@lukaskubanek
lukaskubanek / View+KeyboardAvoidance.swift
Created December 4, 2023 07:28
A patch for SwiftUI views that disables keyboard avoidance
import InterposeKit
import UIKit
import SwiftUI
import SwiftUIIntrospect
extension View {
public func keyboardAvoidanceDisabled() -> some View {
self.introspect(.viewController, on: .iOS(.v17)) { viewController in
if let hostingView = viewController.parent?.view {
if String(describing: type(of: hostingView)).hasPrefix("_UIHostingView") {
@lukaskubanek
lukaskubanek / SwiftUIListRowHighlightFix.swift
Last active March 26, 2024 17:51
A workaround for fixing SwiftUI’s list row highlighting behavior by preventing unwanted delays
import InterposeKit
import SwiftUI
/// A workaround for an issue in SwiftUI related to delayed highlighting of list rows upon user
/// interaction, rendering it inconsistent with UIKit.
///
/// This fix implements the solution proposed by Léo Natan and utilizes `InterposeKit` by Peter
/// Steinberger to modify the behavior of `UICollectionViewCell` instances used internally
/// by SwiftUI.
///
@lukaskubanek
lukaskubanek / fn-shortcuts.md
Last active February 21, 2024 16:26
macOS Monterey Keyboard Shortcuts Leveraging the Fn Key
Shortcut Description Overridable?[^1]
Fn-A Navigate Dock No
Fn-Shift-A Launchpad No
Fn-C Control Center No
Fn-E Emoji & Symbols Yes
Fn-F Enter/Exit Full Screen Yes
Fn-H Desktop No
Fn-M Navigate Main Menu Yes
Fn-N Notifications No
@lukaskubanek
lukaskubanek / Bundle+TestFlight.swift
Last active November 3, 2024 17:20
A code snippet for detecting the TestFlight environment for a macOS app at runtime
/// MIT License
///
/// Copyright (c) 2021 Lukas Kubanek, Structured Path GmbH
///
/// Permission is hereby granted, free of charge, to any person obtaining a copy
/// of this software and associated documentation files (the "Software"), to deal
/// in the Software without restriction, including without limitation the rights
/// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
/// copies of the Software, and to permit persons to whom the Software is
/// furnished to do so, subject to the following conditions:
@lukaskubanek
lukaskubanek / XCTAssertThrowsError.swift
Created March 14, 2021 18:58
XCTAssertThrowsError(…) With Error Equality Check
import XCTest
public func XCTAssertThrowsError<T, E: Error & Equatable>(
_ expression: @autoclosure () throws -> T,
expected expectedError: E,
_ message: String = "",
file: StaticString = #filePath,
line: UInt = #line
) {
XCTAssertThrowsError(try expression(), message, file: file, line: line) { error in
@lukaskubanek
lukaskubanek / NSView Drawing Issue on macOS Big Sur.md
Last active July 18, 2022 08:09
NSView Drawing Issue on macOS Big Sur

This is an excerpt from our internal documentation describing an issue with drawing in NSViews on macOS Big Sur.

1️⃣ Introduction

In macOS Big Sur (probably starting with β9), Apple changed the default contents format for backing layers of NSViews. Instead of an explicit CALayerContentsFormat.RGBA8Uint value, an „Automatic“ value is now used. Even though it also resolves into „RGBA8“ in our testing, it has some serious implications as it breaks assumptions our code relies on.

I first stumbled upon this issue in this tweet by Frank. It links to a thread on Apple Forums by Mark that contains valuable information as well as ideas for workarounds. The changed behavior was also confirmed by Marcin in this tweet.

2️⃣ Impact on Diagrams

@lukaskubanek
lukaskubanek / keybase-github.md
Last active April 7, 2016 12:36
Updating keybase.io public key to work with GitHub
  1. Import keybase.io keys to GPG locally (→ link)
  2. Add new email address to the public key (→ link)
  3. Export the public key and upload it to keybase.io again (→ link)
  4. Configure GPG for Git locally (→ link)
@lukaskubanek
lukaskubanek / OptionalAssignment.swift
Created November 14, 2015 15:50
OptionalAssignment.swift
// Optional Assignment
infix operator =? { associativity right precedence 90 }
/// Given a variable and an optional value it unwraps the optional value
/// and if it is non-nil it assigns the value to the variable. If the value
/// is nil it does nothing.
public func =? <T>(inout variable: T, optionalValue: T?) {
if let value = optionalValue {
variable = value

My Wishes for Swift 3.0

  • Typed errors
  • Property observers from outside as a replacement for KVO
  • Resolving the limitation in failable class initializers which require setting all stored properties before throwing an error or returning nil
  • Operator for reversed ranges (https://medium.com/@icex33/boundary-extension-in-swift-1f577af1aaa)
  • Nested types in generic types
  • Packages (inside frameworks, allowing cyclic dependencies)
  • Members for protocols tied to the protocol type (e.g. for implementing factories on the protocol types)
  • Abstract classes & class methods