Skip to content

Instantly share code, notes, and snippets.

@haikusw
haikusw / View+ParentViewController.swift
Created February 25, 2025 03:56 — forked from harlanhaskins/View+ParentViewController.swift
A SwiftUI modifier for inserting the parent UIViewController in the environment
import Foundation
import SwiftUI
extension View {
/// Adds introspection to find the parent view controller in the view hierarchy and
/// makes that view controller available to downstream views in the view hierarchy.
public func addParentViewControllerIntrospection() -> some View {
modifier(ParentViewControllerEnvironmentModifier())
}
}
@haikusw
haikusw / TestApp.swift
Created December 21, 2024 03:31 — forked from chockenberry/TestApp.swift
Swipe actions breaking ShareLink()
//
// TestApp.swift
// TestApp
//
// Created by Craig Hockenberry on 12/19/24.
//
import SwiftUI
@main
@haikusw
haikusw / moreFinderTerminal.sh
Created September 20, 2024 22:08 — forked from ldavidh/moreFinderTerminal.sh
alternate sel script
#cd into directory in Finder's front window
function cdf() {
finderPath=`osascript -e 'try
tell application "Finder" to set the source_folder to (folder of the front window) as alias
on error
tell application "Finder" to set source_folder to insertion location as alias
end try
return POSIX path of source_folder as string'`
cd "$finderPath"
@haikusw
haikusw / SwiftUIHostingConfiguration.md
Created August 29, 2024 19:01 — forked from simonbs/SwiftUIHostingConfiguration.md
In iOS 16, Apple added UIHostingConfiguration, making it straightforward to use a SwiftUI view in instances of UICollectionViewCell and UITableViewCell. This project shows how UIHostingConfiguration can be backported to iOS 14 by implementing a type that conforms to the UIContentConfiguration protocol.

SwiftUIHostingConfiguration

In iOS 16, Apple added UIHostingConfiguration, making it straightforward to use a SwiftUI view in instances of UICollectionViewCell and UITableViewCell. This gist shows how UIHostingConfiguration can be backported to iOS 14 by implementing a type that conforms to UIContentConfiguration.

Starting from iOS 16, we can use SwiftUI views in an instance of UICollectionView or UITableViewCell like this:

cell.contentConfiguration = UIHostingConfiguration {
    ExampleCellContentView(color: Color(item.color), text: item.text)
}

Swift Project

cd ~/src/swift-project/swift
./utils/update-checkout --clone-with-ssh --clean

Base build

sccache --start-server
#!/bin/sh
SRC1=$HOME/Library/Safari
SRC2=$HOME/Library/Containers/com.apple.Safari/Data/Library/Safari
HOST=$( hostname | sed 's/\..*//' )
HOUR=$( date +"%H" )
DST=$HOME/Sync/Safari/$HOST/$HOUR
mkdir -p $DST 2>/dev/null
cd $SRC1
@haikusw
haikusw / MeshEntity+GenerateSolidInteriorModel.swift
Created January 25, 2024 05:45 — forked from drewolbrich/MeshEntity+GenerateSolidInteriorModel.swift
A RealityKit ModelEntity extension that replaces its model with a new model with reversed triangle indices
//
// MeshEntity+GenerateSolidInteriorModel.swift
//
// Created by Drew Olbrich on 12/16/23.
//
import RealityKit
extension ModelEntity {
//
// ContentView.swift
// RigelianTagger
//
// Created by Berrie Kremers on 05/03/2022.
//
// This shows how a directory structure can be shown in a sidebar, with dynamic loading
// of additional content as the user drills down in the hierarchy.
//
@haikusw
haikusw / Info.plist
Created November 8, 2023 20:55 — forked from georgebrock/Info.plist
AppleScript to handle URLs
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<!-- ... -->
<!-- Add this section: -->
<key>CFBundleURLTypes</key>
<array>
<dict>
@haikusw
haikusw / xcbuild-debugging-tricks.md
Created September 17, 2023 23:54 — forked from ddunbar/xcbuild-debugging-tricks.md
Xcode new build system debugging tricks

New Build System Tricks

Command Line

alias xcbuild=$(xcode-select -p)/../SharedFrameworks/XCBuild.framework/Versions/A/Support/xcbuild
# THIS DOESNT WORK YET: xcbuild openIDEConsole  # … then switch to Xcode ➡️
xcbuild showSpecs
xcbuild build <foo.pif> [—target <target>]