Skip to content

Instantly share code, notes, and snippets.

View bsneed's full-sized avatar

Brandon Sneed bsneed

View GitHub Profile
@bsneed
bsneed / NSObject-extension.m
Created August 3, 2010 23:15
performSelector reimplementation with variable number of params/types and return type.
/*
You can use this to call deprecated methods without warnings (supporting old sdk's for example)
or, you can use it in place of performSelector: where you need non-object params, or multiple
params.
ie: ...
int result = 0;
int index = 12;
NSArray *array = myArray;
@bsneed
bsneed / build_runscript.sh
Created July 21, 2011 06:33
Copy a settings bundle and set a useful version for testflight if its a Debug build. This happens post file copy and won't change your source files.
#!/bin/bash
BUILD_VER=$(/usr/bin/defaults read ${CODESIGNING_FOLDER_PATH}/Info CFBundleVersion)
BUILD_APPNAME=$(/usr/bin/defaults read ${CODESIGNING_FOLDER_PATH}/Info CFBundleDisplayName)
if [ "$CONFIGURATION" == "Debug" ]; then
echo leaving Settings.bundle in place.
/usr/bin/defaults write ${CODESIGNING_FOLDER_PATH}/Info CFBundleDisplayName "WM ß - $BUILD_VER"
else
rm -rf ${CODESIGNING_FOLDER_PATH}/Settings.bundle
@bsneed
bsneed / NSObject+RFExtensions.h
Created October 6, 2012 06:36
perform a block in a background thread, and call a completion block on the main thread when its done.
//
// NSObject+RFExtensions.h
//
// Created by brandon on 10/5/12.
// Copyright (c) 2012 redf.net. All rights reserved.
//
#import <Foundation/Foundation.h>
typedef void (^NSObjectPerformBlock)(id userObject);
@bsneed
bsneed / gist:4321770
Created December 17, 2012 20:19
example poor-mans proxy
- (void)locationManager:(CLLocationManager *)manager monitoringDidFailForRegion:(CLRegion *)region withError:(NSError *)error
{
[delegates callSelector:_cmd argumentAddresses:(__bridge void *)(self), region, error];
//if (delegate && [delegate respondsToSelector:_cmd])
// [delegate locationManager:self monitoringDidFailForRegion:region withError:error];
}
@bsneed
bsneed / uncrustify_objc.cfg
Created January 16, 2013 23:56
My Obj-C uncrustifyX config.
#
# Uncrustify Configuration File
# File Created With UncrustifyX 0.2 (140)
#
# Alignment
# ---------
## Alignment
@bsneed
bsneed / gist:5646807
Last active December 17, 2015 17:29
rehash of callSelector
- (void)makeObjectsPerformSelector:(SEL)aSelector argumentAddresses:(void *)arg1, ...
{
#define kMaximumCallSelectorArguments 20
// if there's nothing in here, GTFO.
if (self.count == 0)
return;
id sampleTarget = [self objectAtIndex:0];
NSMethodSignature *methodSig = [[sampleTarget class] instanceMethodSignatureForSelector:aSelector];
@bsneed
bsneed / SDMacros.h
Last active December 19, 2015 15:59
My simpler reimplementation of @weakify/@strongify.
//
// SDMacros.h
//
// Created by Brandon Sneed on 7/11/13.
// Copyright (c) 2013 SetDirection. All rights reserved.
//
//
// DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
// Version 2, December 2004
//
@bsneed
bsneed / gist:88dc37b724d52bb09291
Created March 30, 2015 20:07
reflection tests
//
// THGDataMapTests.swift
// THGDataMapTests
//
// Created by Brandon Sneed on 3/28/15.
// Copyright (c) 2015 TheHolyGrail. All rights reserved.
//
import UIKit
import XCTest
@bsneed
bsneed / singleton.swift
Created October 5, 2015 21:40 — forked from rothomp3/singleton.swift
Example of building an inheritance-friendly singleton class in Swift
#!/usr/bin/xcrun -sdk macosx swift
import Foundation
public protocol SharedInstanceType
{
init()
}
private struct TokenKey
@bsneed
bsneed / testNSDecimalNumberWrapper.swift
Created November 7, 2015 22:03
Decimal is a struct that wraps NSDecimalNumber so you can use it like other types (Float, Int, Double, Int64, etc)
func testSomeStuff() {
// trying to come up with shit to test.
var d: Decimal = 1234
print(d)
d += 2
print(d)