Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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]?{