Skip to content

Instantly share code, notes, and snippets.

View kluivers's full-sized avatar

Joris Kluivers kluivers

View GitHub Profile
@kluivers
kluivers / gist:7698470
Created November 28, 2013 21:37
Get the model identifier for the current device (on iOS or Mac)
#include <sys/types.h>
#include <sys/sysctl.h>
#if TARGET_OS_IPHONE
char *propertyName = "hw.machine";
#else
char *propertyName = "hw.model";
#endif
size_t size;
@kluivers
kluivers / gist:9808519
Created March 27, 2014 14:16
Responder forwarding
@implementation UIResponder (ResponderForwarding)
- (BOOL) tryToPerformAction:(SEL)action withObject:(id)object
@end
@implementation UIResponder (ResponderForwarding)
- (BOOL) tryToPerformAction:(SEL)action withObject:(id)object
{
if (!action) {
return NO;
@kluivers
kluivers / url-builder.m
Created April 8, 2014 13:22
Builder pattern in Objective-C
NSURL *someURL = [NSURL URLWithBuilderBlock:^(NSURLComponents *builder) {
builder.scheme = @"http";
builder.host = @"joris.kluivers.nl";
builder.path = @"/blog/2013/10/17/nsurlcomponents/";
}];
// url now equals:
// http://joris.kluivers.nl/blog/2013/10/17/nsurlcomponents/