Skip to content

Instantly share code, notes, and snippets.

View aceontech's full-sized avatar

Alex Manarpies aceontech

View GitHub Profile
@aceontech
aceontech / RetainCycleUnitTest.swift
Created March 3, 2017 08:14
Unit test for checking for retain cycles in Swift. Replace `CLASS_YOU_WANT_TO_TEST` with your class name.
func testCleanup() {
// Extend your class inline in order to add closure property `deinitCalled`,
// which indicates when/if your class's deinit() gets called
class ClassUnderTest: CLASS_YOU_WANT_TO_TEST {
var deinitCalled: (() -> Void)?
deinit { deinitCalled?() }
}
// Set up async expectation, which causes the test to wait for `deinitCalled`
@aceontech
aceontech / MovingAverage.h
Created December 17, 2014 10:47
Objective-C utility class for maintaining a moving average over a given time period.
//
// Created by Alex Manarpies on 12/17/14.
//
#import <Foundation/Foundation.h>
/**
* Utility class for maintaining a moving average over a given time period.
* Credits: http://stackoverflow.com/a/14740836/331283
@aceontech
aceontech / CoreDataInMemorySetupExampleSpec.m
Created February 7, 2014 10:04
Setting up an in-memory Core Data stack for unit testing. This example uses Specta, but can be easily be adapted for XCTest.
#import <Specta.h>
#define EXP_SHORTHAND
#import <Expecta.h>
#import <CoreData/CoreData.h>
SpecBegin(CoreDataInMemorySetupExample)
__block NSManagedObjectContext *context;
beforeAll(^{
// ObjectModel from any models in app bundle
@aceontech
aceontech / StringsFileParser.swift
Last active August 1, 2020 19:17
Prototype implementation of a .strings file parser written in Swift, using Parser Combinators, as explained by PointFree.co. See https://www.pointfree.co/collections/parsing/parser-combinators for all videos on this topic.
public protocol FileParser {
func parse(string: String) -> [Entry]
}
public struct FileParserFactory {
public static func unordered() -> FileParser {
UnorderedFileParser()
}
public static func ordered() -> FileParser {
LineOrderedFileParser(unorderedParser: unordered())