0001
0009 import Foundation
0010
0011 func parse| Parse.swift:29 | let object = try parse(json, path) |
| Parse.swift:35 | guard let object = try catchMissingKeyAndReturnNil({ try parse(json, path) }) else { |
(json: AnyObject, _ path: [String]) throws -> AnyObject {
0013 return try path.reduce((json, []), combine: { (a:(object: AnyObject, currentPath: [String]), key: String) in
0014 let currentDict = try NSDictionary.decode(a.object)
0015 guard let result = currentDict[NSString(string: key)] else {
0016 var error = MissingKeyError(key: key, object: currentDict)
0017 error.path = a.currentPath
0018 error.rootObject = json
0019 throw error
0020 }
0021
0022 var path = a.currentPath
0023 path.append(key)
0024 return (result, path)
0025 }).object
0026 }
0027
0028 public func parse| Operators.swift:140 | return try parse(json, path: path.toJSONPathArray(), decode: decode) |
<T>(json: AnyObject, path: [String], decode: (AnyObject throws -> T)) throws -> T {
0029 let object = try parse(json, path)
0030 return try catchAndRethrow(json, path) { try decode(object) }
0031 }
0032
0033 func parseAndAcceptMissingKey| Operators.swift:144 | return try parseAndAcceptMissingKey(json, path: path.toJSONPathArray(), decode: decode) |
<T>(json: AnyObject, path: [String], decode: (AnyObject throws -> T)) throws -> T? {
0035 guard let object = try catchMissingKeyAndReturnNil({ try parse(json, path) }) else {
0036 return nil
0037 }
0038 return try catchAndRethrow(json, path) { try catchNull(decode)(object) }
0039 }
0040
0041
0042
0044 func catchMissingKeyAndReturnNil| Parse.swift:35 | guard let object = try catchMissingKeyAndReturnNil({ try parse(json, path) }) else { |
<T>(closure: Void throws -> T) throws -> T? {
0045 do {
0046 return try closure()
0047 } catch is MissingKeyError {
0048 return nil
0049 }
0050 }
0051
0052 func catchAndRethrow| Parse.swift:30 | return try catchAndRethrow(json, path) { try decode(object) } |
| Parse.swift:38 | return try catchAndRethrow(json, path) { try catchNull(decode)(object) } |
<T>(json: AnyObject, _ path: [String], block: Void throws -> T) throws -> T {
0053 do {
0054 return try block()
0055 } catch let error as DecodingError {
0056 var error = error
0057 error.path = path + error.path
0058 error.rootObject = json
0059 throw error
0060 } catch let error {
0061 throw error
0062 }
0063 }
0064