Skip to content

Instantly share code, notes, and snippets.

@aspitz
aspitz / Table
Created December 11, 2014 14:55
A Table data structure to support UITableView
struct Table<valueType:Equatable>{
var table:[[valueType]] = [[valueType]]()
var sectionCount:Int{
get{
return table.count
}
}
subscript(section:Int) -> [valueType]?{
@aspitz
aspitz / OrderedDictionary
Created November 21, 2014 15:13
Swift implementation of an ordered Dictionary
import Foundation
struct OrderedDictionary<KeyType:Hashable, ValueType:Hashable>{
var keyArray = [KeyType]()
var keyToValue = [KeyType:ValueType]()
subscript(key:KeyType) -> ValueType? {
get{
return keyToValue[key]
}
@aspitz
aspitz / BidirectionalDictionary
Created November 2, 2014 14:54
Swift implementation of a bidirectional dictionary
struct BidirectionalDictionary<KeyType:Hashable, ValueType:Hashable>{
var keyToValue = [KeyType:ValueType]()
var valueToKey = [ValueType:KeyType]()
subscript(key:KeyType) -> ValueType? {
get {
return self.keyToValue[key]
}
set {
self.keyToValue[key] = newValue
@aspitz
aspitz / UIViewShadow
Created October 17, 2013 20:21
Code to add a shadow to a UIView. This code assumes that it's being added/executed inside a UIView or subclass of UIView
self.layer.masksToBounds = NO;
self.layer.shadowOffset = CGSizeMake(2.5, 5);
self.layer.shadowRadius = 5;
self.layer.shadowOpacity = 0.5;
@aspitz
aspitz / UIImage+UIViewCapture
Created August 21, 2013 13:19
Category code to capture a UIView as a UIImage
#import "UIImage+UIViewCapture.h"
#import <QuartzCore/QuartzCore.h>
@implementation UIImage (UIViewCapture)
+ (UIImage *)imageWithView:(UIView *)view{
UIGraphicsBeginImageContextWithOptions(view.bounds.size, view.opaque, 0.0);
[view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage * img = UIGraphicsGetImageFromCurrentImageContext();
@aspitz
aspitz / base64
Created August 13, 2013 12:42
Encode/decode a binary file into/out of base64 from the command line
To encode
> base64 -i [source.binary] -o [destination.base64]
To decode
> base64 -D -i [source.base64] -o [destination.binary]
To encode directly into the clipboard
> base64 < [source.binary] | pbcopy
@aspitz
aspitz / ZZiptastic
Last active December 20, 2015 18:29
A simple class that makes the Ziptastic REST service available to iOS and OSX developers
#import <Foundation/Foundation.h>
extern NSString *const ZZiptasticCityKey;
extern NSString *const ZZiptasticStateKey;
extern NSString *const ZZiptasticCountryKey;
extern NSString *const ZURLHTTPErrorCode;
typedef void (^ZZiptasticBlock)(NSDictionary *location, NSError *error);
@aspitz
aspitz / OrderedDictionary
Created July 31, 2013 13:49
A dictionary that keeps track of the order that elements were added to it
@interface OrderedDictionary : NSObject <NSCopying, NSCoding>{
NSMutableDictionary *_dictionary;
NSMutableArray *_array;
}
@property (readonly) NSUInteger count;
- (id)init;
- (id)initWithCapacity:(NSUInteger)capacity;
+ (id)dictionary;
@aspitz
aspitz / ZDrawView
Last active December 19, 2015 12:18
A subclass of UIView that allows a developer to draw in a view without having to subclass UIView
typedef void (^DrawBlock)(CGContextRef currentContext, CGRect drawRect, UIView *selfView);
@interface ZDrawView : UIView
@property (nonatomic, copy) DrawBlock drawBlock;
- (instancetype)initWithBlock:(DrawBlock)block;
+ (instancetype)viewWithBlock:(DrawBlock)block;
@aspitz
aspitz / .gitignore
Created June 20, 2013 13:40
Base Git Ignore file for Xcode project
.DS_Store
*.swp
*~.nib
build/
*.pbxuser
*.perspective
*.perspectivev3