Skip to content

Instantly share code, notes, and snippets.

View zachwaugh's full-sized avatar

Zach Waugh zachwaugh

View GitHub Profile
@zachwaugh
zachwaugh / switch-shortcut.swift
Last active February 6, 2023 16:15
Swift shortcut for returning and/or assigning the result of switch statement?
// Can currently do this
func titleForSection1(section: Int) -> String? {
switch section {
case 0: return "Foo"
case 1: return "Bar"
default: return nil
}
}
// But I want to do this to remove the redundant returns
@zachwaugh
zachwaugh / fonts.md
Last active August 29, 2015 14:27
Lists all fonts installed on iOS. Helpful to get the correct name when using custom fonts in an app
func printFonts() {
    println("--- Installed fonts ---")
    let families = sorted(UIFont.familyNames() as! [String]) { $0 < $1 }

    for family in families {
        println("family: \(family)")
            
        let fonts = UIFont.fontNamesForFamilyName(family)
        for font in fonts {
@zachwaugh
zachwaugh / Makefile
Last active October 6, 2020 03:36
Swift + Sublime Text 3
# I rarely use make, probably a better way to do some/all of this?
SDK=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk
SOURCES=main.swift
EXECUTABLE=main
all:
swiftc -sdk $(SDK) $(SOURCES) -o $(EXECUTABLE)
clean:
@zachwaugh
zachwaugh / TestApp.swift
Created July 25, 2024 00:45
Sample app to reproduce a ShareLink bug when used in a sheet with a confirmationDialog
import SwiftUI
// Sample app to reproduce ShareLink bug from a sheet
// 1. Run app, tap "Present Modal Sheet"
// 2. Try to Share from the sheet
// 3. It won't present and you'll see an error in the console:
// Attempt to present <UIActivityViewController: 0x102820000> on <_TtGC7SwiftUI19UIHostingControllerGVS_15ModifiedContentVS_7AnyViewVS_12RootModifier__: 0x102020e00> (from <_TtGC7SwiftUI32NavigationStackHostingControllerVS_7AnyView_: 0x103829a00>) which is already presenting <_TtGC7SwiftUI29PresentationHostingControllerVS_7AnyView_: 0x10202a800>.
// 4. Comment out the .confirmationDialog line and it works
// 5. Move .confirmationDialog before .sheet and it works