Skip to content

Instantly share code, notes, and snippets.

View rsaunders100's full-sized avatar

Rob Saunders rsaunders100

View GitHub Profile
@rsaunders100
rsaunders100 / UIView+ViewArranging.h
Created May 15, 2012 17:39
(iOS) Make a view with given subviews arranged linearly (either horizontally or vertically)
//
// UIView+ViewArranging.h
// Created by on 15/05/2012.
//
#import <UIKit/UIKit.h>
typedef enum {
ViewArrangingDirectionHorizontal,
ViewArrangingDirectionVertical
@rsaunders100
rsaunders100 / KDPersistantCache.h
Created April 18, 2012 15:53
Persistently stores and recovers NSCoding compliant objects with a expiry time
//
// KDPersistantCache.h
// KDPrototype
// Stores NSCoding compliant objects persistantly in the NSCachesDirectory
// for a specified period of time.
//
// Created by on 18/04/2012.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//
@rsaunders100
rsaunders100 / AppReSigner.scpt
Created March 22, 2012 17:29
Re-sign .ipa files and replace the embedded.mobileprovision
-- Erica Sadun, http://ericasadun.com
-- iPhone Developer's Cookbook, 3.0 Edition
-- BSD License, Use at your own risk
-- Adapted by Rob Saunders to also replace embeded profiles
--
--
-- save in Script Editor as Application
-- drag files to its icon in Finder
@rsaunders100
rsaunders100 / UIView+ViewExpanding.h
Created March 2, 2012 17:38
UIView+ViewExpanding.h
//
// UIView+ViewExpanding.h
// VodafoneTest
//
// Created by Robert Saunders on 02/03/2012.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//
#import <UIKit/UIKit.h>
@rsaunders100
rsaunders100 / UIImage+ImageSplitting.h
Created February 3, 2012 15:02
(iOS) Split an image into an array of evenly sized CALayers
//
// UIImage+ImageSplitting.h
// Test
//
// Created by Robert Saunders on 03/02/2012.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//
#import <UIKit/UIKit.h>
@rsaunders100
rsaunders100 / UIView+Snapshots.m
Created January 31, 2012 14:11
(iOS) Take image snapshots of the current state of a view.
@interface UIView (UIView_Snapshots)
// Take image snapshots of the current state of a view.
// Use the background color of the superview if you have rounded corners
// If background color is nil the background will be treated as transparent
- (UIImage*) imageOfViewUsingBackgroundColor:(UIColor*)backgroundColorOrNil;
// Will save to the documents directory as XXXX.png
- (void) saveImageOfViewToPNGNamed:(NSString*)fileNameMinusExtension usingBackgroundColor:(UIColor*)backgroundColorOrNil;
@rsaunders100
rsaunders100 / BGBlock.m
Created October 19, 2011 16:29
(iOS) Simple Background - Main Thread with blocks
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^
{
// Do heavy lifting
// Back to the main thread with the result
dispatch_sync(dispatch_get_main_queue(), ^
{
// Update UI etc
}
}
@rsaunders100
rsaunders100 / alert.m
Created September 19, 2011 09:35
(iOS) UIAlert View Example - Has a delegate for Yes/No Taps Will only display popup once
- (void) showConfirmationAlert
{
// A quick and dirty popup, displayed only once
if (![[NSUserDefaults standardUserDefaults] objectForKey:@"HasSeenPopup"])
{
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Question"
message:@"Do you like cats?"
delegate:self
cancelButtonTitle:@"No"
otherButtonTitles:@"Yes",nil];
@rsaunders100
rsaunders100 / FileCommands.m
Created September 18, 2011 15:42
(iOS) Commands to save and load & copy from from the bundle and the documents directory.
+ (NSString*) pathForSaving
{
NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString* documentsDirectory = [paths objectAtIndex:0];
return [documentsDirectory stringByAppendingPathComponent:@"fileName.plist"];
}
+ (void) loadFromDisk {
NSString* path = [MyClass pathForSaving];
@rsaunders100
rsaunders100 / hackFeed.m
Created September 9, 2011 16:14
(iOS) Saves the response of a parsing result to disk and restores it later, for hacking / testing feeds
-(void)processLoginWithData:(NSData*)data {
//
// Pull the data in from disk
//
NSString* responsePath = [[NSBundle mainBundle] pathForResource:@"response" ofType:@"xml"];
NSString* hackedString = [NSString stringWithContentsOfFile:responsePath
encoding:NSUTF8StringEncoding
error:nil];
data = [hackedString dataUsingEncoding:NSUTF8StringEncoding];