Skip to content

Instantly share code, notes, and snippets.

Avatar

Lukas Kubanek lukaskubanek

View GitHub Profile
@lukaskubanek
lukaskubanek / fn-shortcuts.md
Last active Apr 4, 2022
macOS Monterey Keyboard Shortcuts Leveraging the Fn Key
View fn-shortcuts.md
Shortcut Description
Fn-A Navigate Dock
Fn-Shift-A Launchpad
Fn-C Control Center
Fn-E Emoji & Symbols
Fn-F Enter/Exit Full Screen
Fn-H Desktop
Fn-M Navigate Main Menu
Fn-N Notifications
@lukaskubanek
lukaskubanek / Bundle+TestFlight.swift
Last active May 18, 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
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
lukaskubanek / NSView Drawing Issue on macOS Big Sur.md
Last active May 29, 2022
NSView Drawing Issue on macOS Big Sur
View NSView Drawing Issue on macOS Big Sur.md

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
lukaskubanek / keybase-github.md
Last active Apr 7, 2016
Updating keybase.io public key to work with GitHub
View keybase-github.md
  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)
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
View swift-3-wishes.md

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
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) {
self.init()
let pathPtr = UnsafeMutablePointer<NSBezierPath>.alloc(1)
pathPtr.initialize(self)