This file contains hidden or 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
//: Playground - noun: a place where people can play | |
import UIKit | |
enum JSONError : ErrorType { | |
case NoValueForKey(String) | |
case TypeMismatch | |
} | |
public class JSONObject { |
This file contains hidden or 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 | |
import ReactiveCocoa | |
import Orcinus |
This file contains hidden or 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 | |
import CoreData |
This file contains hidden or 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
protocol Debuggable { | |
var debug: Bool { get set } | |
func debugPrint(message: String) | |
} | |
extension Debuggable { | |
func debugPrint(message: String) { | |
if debug { | |
print(message) | |
} |
This file contains hidden or 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
func attemptMap<T, U>(operation: T throws -> U) -> ReactiveCocoa.Signal<T, NSError> -> ReactiveCocoa.Signal<U, NSError> { | |
return { signal in | |
return Signal { observer in | |
signal.observe(next: { value in | |
do { | |
sendNext(observer, try operation(value)) | |
} | |
catch { | |
sendError(observer, error as NSError) |
This file contains hidden or 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
func keyboardWillShow(notification: NSNotification) { | |
print("Showing keyboard") | |
guard let userInfo = notification.userInfo, | |
rectValue = userInfo[UIKeyboardFrameEndUserInfoKey] as? NSValue, | |
rawCurve = userInfo[UIKeyboardAnimationCurveUserInfoKey] as? UInt, | |
duration = userInfo[UIKeyboardAnimationDurationUserInfoKey] as? Double else { | |
return | |
} | |
let keyboardFrame = rectValue.CGRectValue() |
This file contains hidden or 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
// MARK: - Keys | |
import Foundation | |
public protocol JSONKeyType { | |
var JSONKey: String { get } | |
} | |
extension String: JSONKeyType { | |
public var JSONKey: String { |
This file contains hidden or 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 | |
// | |
// MARK: - JSONError Type | |
// | |
public enum JSONError: ErrorType, CustomStringConvertible { | |
case KeyNotFound(key: JSONKeyType) | |
case NullValue(key: JSONKeyType) | |
case TypeMismatch(expected: Any, actual: Any) |
This file contains hidden or 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 UIKit | |
enum MyError: ErrorType { | |
case Oooggh(String) | |
} | |
func errorProne() throws { | |
throw MyError.Oooggh("nope") | |
} |
This file contains hidden or 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
protocol StoryboardInstantiable { | |
static var storyboardName: String { get } | |
static var storyboardIdentifier: String { get } | |
} | |
extension StoryboardInstantiable { | |
static func instantiateFromStoryboard() -> Self { | |
let storyboard = UIStoryboard(name: storyboardName, bundle: nil) | |
guard let vc = storyboard.instantiateViewControllerWithIdentifier(storyboardIdentifier) as? Self else { | |
fatalError("Instantiated view controller does not match type") |