Skip to content

Instantly share code, notes, and snippets.

@ratkins
ratkins / gist:7655315
Last active December 29, 2015 10:09
A technique for injecting a UINavigationController created by UIStoryboard into a Typhoon-managed object

We had the need to expose a UINavigationController created by UIStoryboard to a class that was managed by Typhoon. We were already using a technique to inject a ViewController's properties with Typhoon-managed objects, but we wanted to go the other way around and get the UINavigationController that was created by UIStoryboard into the Typhoon universe.

Because the UIStoryboard (and therefore UINavigationController) doesn't actually exist when Typhoon is doing its thing, we had to create a NavigationControllerProxy that would look it up and return it when it was asked. This could then be injected by Typhoon into any object which neede the UINavigationController:

// NavigationControllerProxy.m

- (UINavigationController *)navigationController {
    return (UINavigationController *)[UIApplication sharedApplication].keyWindow.rootViewController;
}
@ratkins
ratkins / GroupableItem+Builder.h
Last active April 6, 2017 20:22
Avoid polluting an Objective-C implementation with builder-related code by "hiding" it in a category
#import "GroupableItem.h"
@interface GroupableItemBuilder : NSObject
@property (nonatomic, strong) NSString *name;
@property (nonatomic, strong) NSString *groupingKey;
@property (nonatomic, assign) NSInteger second;
@property (nonatomic, assign) NSInteger minute;
@property (nonatomic, assign) NSInteger hour;
@property (nonatomic, assign) NSInteger day;
@ratkins
ratkins / gist:d35e9ca0e033da915fb8
Created July 10, 2014 13:54
Appending table rows.
[self.billingEmailSection.contacts addObject:@""];
NSArray *blankRows = @[
[NSIndexPath indexPathForItem:[self.billingEmailSection.contacts count] inSection:4]
];
[self.tableView insertRowsAtIndexPaths:blankRows withRowAnimation:UITableViewRowAnimationBottom];

Keybase proof

I hereby claim:

  • I am ratkins on github.
  • I am ratkins (https://keybase.io/ratkins) on keybase.
  • I have a public key whose fingerprint is 16B5 B9AC 079B 53F5 47C3 1303 CA4E 3BBF C9E0 008F

To claim this, I am signing this object:

#include "FastLED.h"
#include <stdio.h>
const uint8_t ledPin = 2;
//37 + (18 * 2) + (14 * 4)
const uint16_t kNumLeds = 129;
CRGB leds[kNumLeds];
@ratkins
ratkins / Session.swift
Last active June 18, 2017 10:20
Simple, type-safe networking in Swift with zero dependencies
import Foundation
enum HTTPMethod {
case get
case post(data: Data)
}
protocol Request {
associatedtype ResponseType