Skip to content

Instantly share code, notes, and snippets.

View SeanMcTex's full-sized avatar

Sean "Sharky" McMains SeanMcTex

View GitHub Profile
@SeanMcTex
SeanMcTex / gist:6308966
Last active December 21, 2015 12:58
Unit Tests That Write Themselves: Part One

Unit Tests That Write Themselves: Part One

Unit tests are fantastic. They make code more robust, refactoring less scary, help developers design programs well, and allow machines do more of the monkey work involved in creating a robust app.

But let's face it: unit tests aren’t always the most fun to write. Worse yet, if developers are trying to achieve high code coverage or adhere to Test Driven Development, they will often end up with a lot of repetitive tests.

This is a state of affairs that wouldn't stand for a minute in application code, but which often passes without a second thought in test code. But if we're serious about testing, this should bother us. We should strive to keep our tests as [^1]DRY as we keep our app.

How do we achieve this? In this article, we'll implement a superclass for test suites with common elements, and see how to use the Objective-C runtime to make sure those tests are named meaningfully. (Teaser: in the followup article, we'll see a technique that delves deeper into r

@SeanMcTex
SeanMcTex / gist:6318927
Last active December 21, 2015 14:19
Unit Tests That Write Themselves: Part Two

Unit Tests That Write Themselves: Part Two

In the first article in this series, we set up an abstract parent class for our view controller tests and used Objective C's runtime library to create dynamically named tests for all of its concrete subclasses. This technique can save a lot of time, but we still have to remember to create a new test case for each view controller class.

Is it possible to make unit tests even more automatic? By gazing deep into the occult mysteries of the runtime system, we will answer this question and, if we're lucky, discover a little bit about love along the way. (Editor's Note: We will not actually discover anything about love.)

If you'd like to follow along with some functional code, you can download the sample project from GitHub.

The Case for Automated Test Creation

We couldn’t find that file to show.
@SeanMcTex
SeanMcTex / swift-cheat-sheet.md
Created June 4, 2014 15:40
Quick Reference for the Most Commonly Needed Accessibility Functionality in Swift for iOS

Accessibility Cheat Sheet for Swift

The Basics

fireButton.accessibilityLabel = NSLocalizedString( "Fire Weapons", comment: "Fire weapons button label" )
fireButton.isAccessibilityElement = true
fireButton.accessibilityHint = "Clearly, you should push this button to shoot your weapons at the bad guys"

Notifications

UIAccessibilityPostNotification( UIAccessibilityScreenChangedNotification, self.fireButton )
UIAccessibilityPostNotification( UIAccessibilityLayoutChangedNotification, nil )
# WWDC 2015 Wish List & Predictions, the Developer's Perspective
Mutual Mobile has been very lucky this year to have a number of our devs awarded tickets to attend WWDC. As the time grows close, speculation about what we'll be seeing this year is reaching a fever pitch. As developers, we have a lot of stake in what Apple reveals in a couple of short weeks, and we've had some great discussions about what we expect to see and what we are hoping for. Here are a number of the things we're wishing for and estimates of how likely we think it is that our dreams will come true.
## New Apple TV
The last time Apple mentioned the Apple TV, they lowered the price: "starting at $69". The "starting at" makes it a near certainty that there's an updated Apple TV in the works, and rumors seem to indicate that an SDK for doing development for the updated box is a very likely as well. An SDK would allow video providers to create new apps to share video content from a variety of new sources, and to enrich that video content w

WWDC 2015 Wish List & Predictions, the Developer's Perspective

Mutual Mobile has been very lucky this year to have a number of our devs awarded tickets to attend WWDC. As the time grows close, speculation about what we'll be seeing this year is reaching a fever pitch. As developers, we have a lot of stake in what Apple reveals in a couple of short weeks, and we've had some great discussions about what we expect to see and what we are hoping for. Here are a number of the things we're wishing for and estimates of how likely we think it is that our dreams will come true.

New Apple TV

The last time Apple mentioned the Apple TV, they lowered the price: "starting at $69". The "starting at" makes it a near certainty that there's an updated Apple TV in the works, and rumors seem to indicate that an SDK for doing development for the updated box is a very likely as well. An SDK would allow video providers to create new apps to share video content from a variety of new sources, and to enrich that video content w

@SeanMcTex
SeanMcTex / PinToSafeArea.cs
Last active August 9, 2024 07:11
Restrict Unity UI to an iPhone X or other Mobile Device's Safe Area
using UnityEngine;
/// <summary>
/// Resizes a UI element with a RectTransform to respect the safe areas of the current device.
/// This is particularly useful on an iPhone X, where we have to avoid the notch and the screen
/// corners.
///
/// The easiest way to use it is to create a root Canvas object, attach this script to a game object called "SafeAreaContainer"
/// that is the child of the root canvas, and then layout the UI elements within the SafeAreaContainer, which
/// will adjust size appropriately for the current device./// </summary>
@SeanMcTex
SeanMcTex / MeshMeasure.cs
Created January 24, 2019 23:43
Unity Utility to display bounds of mesh objects in world space
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
/// <summary>
/// In order to help gauge the size of mesh objects,
/// this script displays the dimensions in world space of a selected object
/// with a MeshRenderer attached whenever it's selected.
/// </summary>
@SeanMcTex
SeanMcTex / README-Template.md
Created March 7, 2019 15:01 — forked from PurpleBooth/README-Template.md
A template to make good README.md

Project Title

One Paragraph of project description goes here

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.

Prerequisites

@SeanMcTex
SeanMcTex / FilteredTextField.md
Created May 8, 2020 20:05
A pitfall to avoid when filtering SwiftUI TextFields

Today’s very hard-won lesson: be careful how you do TextField content filtering! We were filtering input to a text field (making sure the field only accepted numbers, etc.) like so:

@Binding var value: String
TextField( placeholder, text: $value )
    .onReceive( Just( value ), perform: { 
		self.value = self.contentType.filterCharacters( oldValue: $0 ) 
	})