Skip to content

Instantly share code, notes, and snippets.

View aceontech's full-sized avatar

Alex Manarpies aceontech

View GitHub Profile
@aceontech
aceontech / UILabel+AOTSizingUtilities.h
Created February 3, 2015 16:14
Category on UILabel for easily sizing a label to fit in a given width.
//
// Created by Alex Manarpies on 03/02/15.
//
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
@interface UILabel (AOTSizingUtilities)
- (void)aot_sizeToFitInWidth:(CGFloat)width;
@aceontech
aceontech / ImprovedBuilderPattern.swift
Created March 25, 2016 11:42
Improved builder pattern with anonymous closures
class SomeClass {
var someSubview:UIView = {
let v = UIView()
v.someProperty = "You want to initalize"
v.anotherProperty = "You may want to initialize"
return v
}()
}
@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 / 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())