Skip to content

Instantly share code, notes, and snippets.

@BenedictC
BenedictC / Async test functions
Created January 26, 2014 12:05
Functions for running the run loop during tests with Xcode.
/*
Functions for firing a runloop while performing asynchronous tests. Add them at the top of the .m file.
-(void)testExample {
__block NSInteger count = 0;
dispatch_async(dispatch_get_main_queue(), ^{
count = 1;
});
@BenedictC
BenedictC / gist:4246759
Created December 9, 2012 20:03
A marco for creating enums with values which can be logged (inspired by http://rentzsch.tumblr.com/post/37512716957/enum-nsstring and long train journey).
#define EMKStringableEnum(ENUM_NAME, ENUM_VALUES...) \
\
typedef enum { \
ENUM_VALUES \
} ENUM_NAME; \
\
\
\
static NSString * ENUM_NAME##ToString(int enumValue) { \
static NSString *enumDescription = @"" #ENUM_VALUES; \
@BenedictC
BenedictC / proto+posing.m
Created August 5, 2012 10:19
Prototype inheritance and posing for Objective-C
//
// proto+posing.m
//
// Created by Benedict Cohen on 04/08/2012.
// Copyright (c) 2012 Benedict Cohen. All rights reserved.
//
/*
The motivation for this code was to find a way to create subclasses which only differ slightly to their super classes
without having to create a new file. The solution was inspired by prototype inheritance found in Javascript (and IO).
@BenedictC
BenedictC / NSTimer+EMKBlocks
Created April 16, 2012 11:03
NSTimer+Block category. Schedule a timer and use a block as the callback.
@interface NSTimer (EMKTimerBlocks)
+(id)EMK_scheduleTimerWithTimeInterval:(NSTimeInterval)interval repeats:(BOOL)repeats block:(void(^)(NSTimer *))block;
@end
@implementation NSTimer (EMKTimerBlocks)
@BenedictC
BenedictC / protectedMethods.m
Created March 7, 2012 19:51
Faking Protected Methods in Objective-C
//
// main.m
// Protected
//
// Created by Benedict Cohen on 07/03/2012.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//
//
// Unlike other object orientated languages Objective-C does not
// provide a mechanism for scoping methods as public, protected or private.
@BenedictC
BenedictC / Record.h
Created January 11, 2012 14:52
Conceptually similar to a struct, but with object compatibility and memory management.
//
// Record.h
//
// Created by Benedict Cohen on 10/01/2012.
// Copyright (c) 2012 Benedict Cohen. All rights reserved.
//
//
/*