Skip to content

Instantly share code, notes, and snippets.

@loganwright
loganwright / TimeOfDay.swift
Created June 2, 2015 14:20
A structure for holding and referencing the time of day
struct TimeOfDay {
// MARK: Public Properties
var hours: Int
var minutes: Int
var stringRepresentation: String {
var stringRepresentation = hours < 10 ? "0" : ""
stringRepresentation += "\(hours):\(minutes)"
@loganwright
loganwright / xcshortcuts.md
Created June 9, 2015 15:39
Xcode Shortcuts

##Useful Shortcuts

Here's a pretty decent reference as well: http://i.stack.imgur.com/Buohl.jpg

###Must Haves!

cmd + shift + o -- quick navigator -- works with classes, structs, functions, etc.

cmd + shift + j -- Show current file in navigator. Pairs well w/ quick navigator to see where the file fits into the full app.

@loganwright
loganwright / Timer.md
Created June 9, 2015 21:58
Timer struct for running very simple, and imprecise measuring of operations

#Timer

struct Timer : Printable {
    let start = NSDate()
    let name: String
    var description: String {
        let now = NSDate()
        let dif = now.timeIntervalSince1970 - start.timeIntervalSince1970
 let roundedDif = Double(round(1000 * dif)/1000)
import Foundation
extension Dictionary {
mutating public func setValue(val: AnyObject, forKeyPath keyPath: String) {
var keys = keyPath.componentsSeparatedByString(".")
guard let first = keys.first as? Key else { print("Unable to use string as key on type: \(Key.self)"); return }
keys.removeAtIndex(0)
if keys.isEmpty, let settable = val as? Value {
self[first] = settable
} else {
@loganwright
loganwright / After.swift
Last active October 28, 2015 14:24
After
func After(after: NSTimeInterval, op: () -> ()) {
After(after, op: op, completion: nil)
}
func After(after: NSTimeInterval, numberOfTimes: Int, op: () -> (), completion: Void -> Void = {}) {
let numberOfTimesLeft = numberOfTimes - 1
let wrappedCompletion: Void -> Void
if numberOfTimesLeft > 0 {
wrappedCompletion = {
After(after, numberOfTimes: numberOfTimesLeft, op: op, completion: completion)

A basic wrapper for dispatch operations in Swift. Syntax example:

    Qu.Background {
        // Sleep for long operation
        sleep(4)
        log("1")
    } .Also {
        sleep(4)
 log("2")
@loganwright
loganwright / Log.swift
Created July 28, 2015 23:56
Swift Logging
func Log(message: String, file: String = __FUNCTION__, function: String = __FILE__, line: Int = __LINE__, column: Int = __COLUMN__) {
println("\(file) : \(function) : \(line) : \(column) - \(message)")
}
@loganwright
loganwright / EnumExtensions.swift
Last active July 15, 2016 18:31
Int enum type extensions
protocol RawIntInitable {
init?(rawValue: Int)
}
extension RawIntInitable {
static var allCases: [Self] {
var caseIndex = 0
let generator = anyGenerator { Self(rawValue: caseIndex++) }
return Array(generator)
@loganwright
loganwright / tableViewCellBindingData.swift
Created October 9, 2015 03:13
TableViewCell Binding Data
protocol Configurable {
func configure<T : TableViewCellConvertible>(model: T)
}
protocol TableViewCellConvertible {
typealias CellType : UITableViewCell, Configurable
var identifier: String { get }
}
extension TableViewCellConvertible {