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: