Skip to content

Instantly share code, notes, and snippets.

View lukaskubanek's full-sized avatar

Lukas Kubanek lukaskubanek

View GitHub Profile
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 / 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 /
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 / Bundle+TestFlight.swift
Last active July 5, 2024 10:55
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 / 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 / NSView Drawing Issue on macOS Big
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 /
Last active April 7, 2016 12:36
Updating public key to work with GitHub
  1. Import keys to GPG locally (→ link)
  2. Add new email address to the public key (→ link)
  3. Export the public key and upload it to again (→ link)
  4. Configure GPG for Git locally (→ link)
lukaskubanek / OptionalAssignment.swift
Created November 14, 2015 15:50
// 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 (
  • 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
lukaskubanek / FailableMap.swift
Created October 13, 2015 07:28
// FailableMap.swift
// Created by Lukas Kubanek on 06/10/15.
// Copyright © 2015 Lukas Kubanek. All rights reserved.
public extension Array {
/// Maps the transform over `self` and if **all** calls return a non-nil result it returns