Skip to content

Instantly share code, notes, and snippets.

View jqsilver's full-sized avatar

Andy Bartholomew jqsilver

  • Airbnb
  • Los Angeles
View GitHub Profile
// MyClass.swift
// MinimalCrashExample
//
// Created by Andy Bartholomew on 1/4/16.
import Foundation
class MyStruct {
var someValue: Int
@jqsilver
jqsilver / gist:82a515bfaca9a8552ad0
Last active August 29, 2015 14:23
Alamofire serializer for non-classes
typealias JSONDict = [String: AnyObject]
// wrapping structs
private class Box<T> {
let contents: T
init(contents: T) {
self.contents = contents
}
}
@jqsilver
jqsilver / JSONExtractor.swift
Last active August 29, 2015 14:12
Building models from json - inspired by CommandShift
import Foundation
// Turning the attempt() function into an object with state, primarly to get rid of the inout param
// http://commandshift.co.uk/blog/2014/12/28/nice-web-services-swift-edition/
protocol BlankInitable {
init()
}
extension Int : BlankInitable {}
@jqsilver
jqsilver / gist:9c5962bf93f5dadc9d15
Last active August 29, 2015 14:07
swift error communcation: tuple versus enum
// Tuple
// Pros: simple
// Issues:
// what if you get no result, but also no error?
// what if you get a result, but also an error?
func trySomething() -> (String?, NSError?) {
if let result = something() {
return (result, nil)
} else {