Skip to content

Instantly share code, notes, and snippets.

@HiddenJester
HiddenJester / Color+UIColor.swift
Last active July 13, 2024 09:32
A simple extension to SwiftUI Color that bridges over the "missing" colors from UIColor. Write `Text("Hello").foregroundColor(.label)` instead of `Text("Hello").foregroundColor(Color(UIColor.label))`
//
// Color+UIColor.swift
// Swatches
//
// Created by Timothy Sanders on 2019-11-15.
import Foundation
import SwiftUI
import UIKit
@HiddenJester
HiddenJester / UnitTestingSceneDelegateGist.md
Last active March 20, 2024 14:38
Mocking SceneDelegate for Unit Tests on iOS 13

Replacing the SceneDelegate When Running Unit Tests

Overview

I've been working through the exercises in the excellent iOS Unit Testing by Example book by Jon Reid, which I highly recommend. However, the book is in beta at the moment and there are some curveballs thrown by iOS 13 that aren't handled in the text yet. Specifically, when I hit the section about using a testing AppDelegate class I thought "This is very good. But what about the SceneDelegate?"

In Chapter 4 the recommendation is to remove the @UIApplicationMain decoration and make a manual top-level call to UIApplicationMain. To wit:

import UIKit
@HiddenJester
HiddenJester / WatchKit Versioning pre-commit hook
Last active August 29, 2015 14:20
A script usable as a git pre-commit hook that sets the CFBundleVersion of a specified plist to a count of commits in the repository. This is useful for WatchKit apps that cannot run a Run Scripts phase, but must sync version information to the host app.
#!/bin/sh
# Hacky script to update the version of the WatchKit App bundle version to everything else. All of the other targets
# a run script phase that uses setbuildversion.sh out of HJSKit to set the build version to the commit info from git.
# But WatchKit apps can't have a run script phase yet so this pre-commit script mimics the effects but actually edits
# the Info.plist used by by the WatchKit target. Pieces of this are from buildversion.sh, choppped & screwed.
# Redirect output to stderr.
exec 1>&2
@HiddenJester
HiddenJester / KeepViewAboveKeyboard.swift
Last active August 29, 2015 14:10
Simple widget to manage a simple UIView with child views that need to be put above the keyboard.
// NOTE 2015-04-22: This is out of date, but my current implementation has a couple of different tricks and ends up
// being multiple source files and isn't really suitable for gist-posting. I'm currently looking at putting all of HJSKit
// up on GitHub but that's a low-priority project. If you are interested in using something like this contact me (Tim Sanders)
// and I'll get you the latest code.
//
// KeepViewAboveKeyboard.swift
// HJSExtension
//
// Created by Timothy Sanders on 2014-12-04.
// Copyright (c) 2014 HIddenJester Software. All rights reserved.