This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
typealias JSONDict = [String: AnyObject] | |
// wrapping structs | |
private class Box<T> { | |
let contents: T | |
init(contents: T) { | |
self.contents = contents | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// MyClass.swift | |
// MinimalCrashExample | |
// | |
// Created by Andy Bartholomew on 1/4/16. | |
import Foundation | |
class MyStruct { | |
var someValue: Int |