Skip to content

Instantly share code, notes, and snippets.


Peter Steinberger steipete

View GitHub Profile
steipete / ViewExtensions.swift
Created Feb 24, 2021
If you use it please credit PSPDFKit GmbH. MIT License
View ViewExtensions.swift
import Foundation
import SwiftUI
@available(iOS 13.0, *)
extension View {
/// Wraps view into an AnyView
func eraseToAnyView() -> AnyView {
steipete / ContentView.swift
Last active Feb 20, 2021
FB9013209: SwiftUI: Preview and actual layout differ in this example. (SwiftUI Bug)
View ContentView.swift
// ContentView.swift
// Shared
// Created by Peter Steinberger on 20.02.21.
import SwiftUI
struct SettingsGroup<Content: View>: View {
View LayoutPlayground.swift
//: A Cocoa based Playground to present user interface
import SwiftUI
import PlaygroundSupport
struct ContentView: View {
var body: some View {
HStack {
VStack {
HStack {
steipete / KeyCommand.swift
Last active Feb 20, 2021
Add Keyboard Shortcuts to SwiftUI on iOS 13 when using `UIHostingController`. Requires using KeyboardEnabledHostingController as hosting class) See
View KeyCommand.swift
// KeyCommand.swift
// Adds Keyboard Shortcuts to SwiftUI on iOS 13
// See
// License: MIT
// Usage: (wrap view in `KeyboardEnabledHostingController`)
// Button(action: {
// print("Button Tapped!!")
// }) {
steipete / with.swift
Created Jan 28, 2021
with and then for UIKit and SwiftUI
View with.swift
/// Perform an immediate mutation of `subject`. The `transform` function may
/// just mutate the given `subject` or replace it entirely.
/// - Parameters:
/// - subject: A value to be transformed.
/// - transform: A closure that mutates or replaces the `subject`.
@inlinable func with<T>(_ subject: T, _ transform: (_ subject: inout T) throws -> Void) rethrows -> T {
var subject = subject
try transform(&subject)
return subject
steipete / TapAndFadeExample.swift
Last active Jan 24, 2021
How to build Tap-And-Fade using SwiftUI instead of a hard deselect. The default in SwiftUI is too hard and doesn't feel right.
View TapAndFadeExample.swift
// Helper to hold the parent VC weakly
class WeakViewControllerHolder: ObservableObject {
weak var vc: UIViewController?
init(_ vc: UIViewController) { = vc
@available(iOS 13.0, *)
View gist:7181cf321d979d734c5acd2326f6c33f
Process: SafariBookmarksSyncAgent [62985]
Path: /Library/Developer/CoreSimulator/Profiles/Runtimes/iOS 13.7.simruntime/Contents/Resources/RuntimeRoot/System/Library/CoreServices/SafariSupport.bundle/SafariBookmarksSyncAgent
Identifier: SafariBookmarksSyncAgent
Version: 609 (609.
Code Type: X86-64 (Translated)
Parent Process: launchd_sim [46734]
Responsible: SimulatorTrampoline [823]
User ID: 501
Date/Time: 2020-11-29 13:42:02.003 +0100
steipete / Architecture.swift
Last active Feb 5, 2021
Detect if a process runs under Rosetta 2 on Apple Silicon M1 or native. Works for macOS and iOS.
View Architecture.swift
@objc(PSTArchitecture) class Architecture: NSObject {
/// Check if process runs under Rosetta 2.
/// Use to disable tests that use WebKit when running on Apple Silicon
/// FB8920323: Crash in WebKit memory allocator on Apple Silicon when iOS below 14
/// Crash is in JavaScriptCore: bmalloc::HeapConstants::HeapConstants(std::__1::lock_guard<bmalloc::Mutex> const&)
@objc class var isRosettaEmulated: Bool {
// Issue is specific to Simulator, not real devices
#if targetEnvironment(simulator)
return processIsTranslated() == EMULATED_EXECUTION
steipete / NSDictionary+CaseInsensitive.h
Last active Dec 2, 2020
Case Insensitive NSDictionary subclass. This seems like a lost art, so I'm sharing it here. License: MIT,
View NSDictionary+CaseInsensitive.h
/// Higher-order functions for `NSDictionary`.
@interface NSDictionary <KeyType, ObjectType> (PSPDFFoundation)
/// Converts the current dictionary into a case insensitive one.
@property (nonatomic, readonly) NSDictionary<NSString *, ObjectType> *pst_caseInsensitiveDictionary;
steipete / Default.xcconfig
Created Nov 6, 2020
Hack to exclude arm64 when building Mac Catalyst in Xcode 12.2
View Default.xcconfig
// Hack to exclude arm64 when building Mac Catalyst in Xcode 12.2
// If this is not set and we do not set macosx as SUPPORTED_PLATFORMS, then selecting Mac as target forces arm64.
// This can be worked around by setting ONLY_ACTIVE_ARCH to NO (slow) or using the EXCLUDED_ARCHS trick
// Inspired by
EXCLUDED_ARCHS__IS_MACCATALYST_YES__NATIVE_ARCH_64_BIT_x86_64=arm64 arm64e armv7 armv7s armv6 armv8