Skip to content

Instantly share code, notes, and snippets.


Lukas Kubanek lukaskubanek

View GitHub Profile
lukaskubanek /
Last active Jan 9, 2023
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 Nov 13, 2022
A code snippet for detecting the TestFlight environment for a macOS app at runtime
View Bundle+TestFlight.swift
import Foundation
import Security
extension Bundle {
/// Returns whether the bundle was signed for TestFlight beta distribution by checking
/// the existence of a specific extension (marker OID) on the code signing certificate.
/// This routine is inspired by the source code from ProcInfo, the underlying library
/// of the WhatsYourSign code signature checking tool developed by Objective-See. Initially,
lukaskubanek / XCTAssertThrowsError.swift
Created Mar 14, 2021
XCTAssertThrowsError(…) With Error Equality Check
View XCTAssertThrowsError.swift
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 Jul 18, 2022
NSView Drawing Issue on macOS Big Sur
View NSView Drawing Issue on macOS Big

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

View Example.swift
import AppKit
class ClockView: NSView {
var date: Date?
class ClockViewController: NSViewController {
lukaskubanek /
Last active Apr 7, 2016
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)
View 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 (
  • 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
View FailableMap.swift
// 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
View NSBezierPath+CGPath.swift
import AppKit
public extension NSBezierPath {
public convenience init(path: CGPath) {
let pathPtr = UnsafeMutablePointer<NSBezierPath>.alloc(1)