Skip to content

Instantly share code, notes, and snippets.

import Foundation
public func printStackDepth(
label: String? = nil,
fileID: StaticString = #fileID,
line: UInt = #line
) {
let thread = pthread_self()
let stackAddress = UInt(bitPattern: pthread_get_stackaddr_np(thread))
var used: UInt = 0
withUnsafeMutablePointer(to: &used) {
import ComposableArchitecture
import SwiftUI
/// A property wrapper type that can designate properties of an app state that can be expressed as
/// signals in SwiftUI views.
@propertyWrapper
public struct StateAction<Action> {
struct ProjectedAction: Equatable {
let action: Action
let token: UUID
import SwiftUI
struct ContentView: View {
@State var selected = 0
@State var count: Int = 100
@State var position: CGPoint = .zero
var body: some View {
VStack {
Picker(selection: $selected) {
Text("Mask").tag(0)
import XCTestDynamicOverlay
func f(_ f: @autoclosure () -> String) {}
func fa(_ f: @autoclosure () async -> String) async {}
func ft(_ f: @autoclosure () throws -> String) {}
func fat(_ f: @autoclosure () async throws -> String) async {}
func check() async throws {
f(unimplementedAutoclosure(placeholder: "")())
await fa(unimplementedAutoclosure(placeholder: "")())
@tgrapperon
tgrapperon / LoadAndNavigateStyle.swift
Last active October 18, 2023 12:25
This gist demonstrates how to achieve a "Load and Navigate" navigation style using `NavigationStack` on iOS 16.
// This file is self contained and can be copy/pasted in place of the `ContentView.swift` in a default iOS 16/macOS 13 app.
import SwiftUI
struct ContentView: View {
@State var path: NavigationPath = .init()
@State var isLoading1: Bool = false
@State var isLoading2: Bool = false
@State var isLoading3: Bool = false
@tgrapperon
tgrapperon / LICENSE
Created November 18, 2022 04:02
This license applies by default to all my public Gists, unless otherwise specified.
MIT License
Copyright (c) 2022 Thomas Grapperon
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:

FB11244375: Xcode shows an error message when importing a module that declares a typealias to a protocol with a primary associated type

Description

Xcode 14beta5 shows a message stating that "An internal error occurred. Source editor functionality is limited. Attempting to restore..." when importing a module that declare a typealias to a protocol with a primary associated type (and where the alias specifies the primary associated type, generically or not). To reproduce, create a SwiftPM package with two modules A and B having A as a dependency. In the module A, declare:

public protocol Foo<Bar> {
  associatedtype Bar
}
import ComposableArchitecture
import SwiftUI
public enum ControlledStore {}
extension ControlledStore {
public enum Command: Equatable {
case run
case pause
}
import SwiftUI
struct ContentView: View {
@State var path: [String] = []
func navigationButton(value: String) -> some View {
NavigationButton {
path.append(value)
} label: {
Text("NavigationButton")
@tgrapperon
tgrapperon / JuxtaposedView.swift
Last active November 16, 2022 17:21
SwiftUI modifier to juxtapose a view to a root view without affecting the layout of the root view.
import SwiftUI
public extension View {
func juxtapose<Content>(
edge: Edge = .top,
spacing: CGFloat = 8,
@ViewBuilder content: @escaping () -> Content
) -> some View where Content: View {
modifier(
JuxtaposedViewModifier(