Skip to content

Instantly share code, notes, and snippets.

View ansonj's full-sized avatar

Anson Jablinski ansonj

View GitHub Profile
@ansonj
ansonj / throw_test.swift
Created May 28, 2020 14:38
Throwing inside a guard
/// Lesson learned:
/// Inside a throwing function...
/// if a `guard` condition calls a second function that ends up throwing...
/// the second function's error is immediately propagated outside of the function.
/// Execution does not enter the `else` block of the `guard` clause.
struct PlaygroundError: Error {
let message: String
}
@ansonj
ansonj / main.m
Created April 24, 2020 16:04
Obj-C experiment: String equality
#import <Foundation/Foundation.h>
#define SAMPLE @"one sample string value"
NSString *addressOf(id object) {
return [NSString stringWithFormat:@"%p", object];
}
int main(int argc, const char * argv[]) {
@autoreleasepool {
@ansonj
ansonj / RunTests.swift
Created May 14, 2018 20:44
Run XCTests from inside a Swift Playground
import XCTest
public func runTests(inClass testClass: XCTestCase.Type) {
let testSuite = testClass.defaultTestSuite
testSuite.run()
guard let testRun = testSuite.testRun else {
preconditionFailure("Couldn't run tests in \(testClass)")
}
let failCount = testRun.totalFailureCount
guard failCount == 0 else {
@ansonj
ansonj / main.m
Last active May 2, 2016 16:25
Testing performance of filling an NSMutableArray
//
// main.m
// ArrayInitialization
//
// Created by Anson Jablinski on 5/2/16.
// Copyright © 2016 ForeFlight. All rights reserved.
//
#import <Foundation/Foundation.h>
@ansonj
ansonj / repeater.swift
Last active August 29, 2015 14:17
Repeater function in Swift
// Runs in a Playground
func repeat(function: () -> (), untilNoChangeTo sentinel: () -> String) {
var initial, final: String
do {
initial = sentinel()
function()
final = sentinel()
} while initial != final