0001
0009 import Foundation
0010
0011
0013 infix operator => { associativity right precedence 150 }
0014 infix operator =>? { associativity right precedence 150 }
0015
0016 public func => <T: Decodable>(lhs: AnyObject, rhs: String) throws -> T {
0018 return try parse(lhs, path: rhs, decode: T.decode)
0019 }
0020
0021 public func => (lhs: AnyObject, rhs: String) throws -> AnyObject {
0023 return try parse(lhs, path: rhs, decode: { $0 })
0024 }
0025
0026 public func => <T: Decodable>(lhs: AnyObject, rhs: String) throws -> T? {
0028 return try parse(lhs, path: rhs, decode: catchNull(T.decode))
0029 }
0030
0031
0033 public func => <T: Decodable>(lhs: AnyObject, rhs: String) throws -> [T] {
0035 return try parse(lhs, path: rhs, decode: decodeArray(T.decode))
0036 }
0037
0038 public func => <T: Decodable>(lhs: AnyObject, rhs: String) throws -> [T]? {
0040 return try parse(lhs, path: rhs, decode: catchNull(decodeArray(T.decode)))
0041 }
0042
0043 public func => <T: Decodable>(lhs: AnyObject, rhs: String) throws -> [T?] {
0045 return try parse(lhs, path: rhs, decode: decodeArray(catchNull(T.decode)))
0046 }
0047
0048 public func => <T: Decodable>(lhs: AnyObject, rhs: String) throws -> [T?]? {
0050 return try parse(lhs, path: rhs, decode: catchNull(decodeArray(catchNull(T.decode))))
0051 }
0052
0053
0055 public func => <T: Decodable>(lhs: AnyObject, rhs: String) throws -> [String: T] {
0057 return try parse(lhs, path: rhs, decode: decodeDictionary(String.decode, elementDecodeClosure: T.decode))
0058 }
0059
0060 public func => <T: Decodable>(lhs: AnyObject, rhs: String) throws -> [String: T]? {
0062 return try parse(lhs, path: rhs, decode: catchNull(decodeDictionary(String.decode, elementDecodeClosure: T.decode)))
0063 }
0064
0065 public func => <K: Decodable>(lhs: AnyObject, rhs: String) throws -> [K: AnyObject]? {
0067 return try parse(lhs, path: rhs, decode: catchNull(decodeDictionary(K.decode, elementDecodeClosure: {$0})))
0068 }
0069
0070
0072 public func =>? (lhs: AnyObject, rhs: String) throws -> AnyObject? {
0074 return try parseAndAcceptMissingKey(lhs, path: rhs, decode: { $0 })
0075 }
0076
0077 public func =>? <T: Decodable>(lhs: AnyObject, rhs: String) throws -> T? {
0079 return try parseAndAcceptMissingKey(lhs, path: rhs, decode: T.decode)
0080 }
0081
0082
0084 public func =>? <T: Decodable>(lhs: AnyObject, rhs: String) throws -> [T]? {
0086 return try parseAndAcceptMissingKey(lhs, path: rhs, decode: decodeArray(T.decode))
0087 }
0088
0089 public func =>? <T: Decodable>(lhs: AnyObject, rhs: String) throws -> [T?]? {
0091 return try parseAndAcceptMissingKey(lhs, path: rhs, decode: decodeArray(catchNull(T.decode)))
0092 }
0093
0094
0096 public func =>? <T: Decodable>(lhs: AnyObject, rhs: String) throws -> [String: T]? {
0098 return try parseAndAcceptMissingKey(lhs, path: rhs, decode: decodeDictionary(String.decode, elementDecodeClosure: T.decode) )
0099 }
0100
0101 public func =>? <K: Decodable>(lhs: AnyObject, rhs: String) throws -> [K: AnyObject]? {
0103 return try parseAndAcceptMissingKey(lhs, path: rhs, decode: decodeDictionary(K.decode, elementDecodeClosure: {$0}))
0104 }
0105
0106
0107
0109 public func => (lhs: String, rhs: String) -> String {
0112 return lhs + String(JSONPathSeparator) + rhs
0113 }
0114
0115 http://stackoverflow.com/questions/1879860/most-reliable-split-characterprivate let JSONPathSeparator| Operators.swift:112 | return lhs + String(JSONPathSeparator) + rhs |
| Operators.swift:123 | return self.characters.split(JSONPathSeparator).map(String.init) |
= Character("\u{0}")
0120
0121 private extension String {
0122 func toJSONPathArray| Operators.swift:140 | return try parse(json, path: path.toJSONPathArray(), decode: decode) |
| Operators.swift:144 | return try parseAndAcceptMissingKey(json, path: path.toJSONPathArray(), decode: decode) |
() -> [String] {
0123 return self.characters.split(JSONPathSeparator).map(String.init)
0124 }
0125 }
0126
0127
0129 func catchNull| Operators.swift:28 | return try parse(lhs, path: rhs, decode: catchNull(T.decode)) |
| Operators.swift:40 | return try parse(lhs, path: rhs, decode: catchNull(decodeArray(T.decode))) |
| Operators.swift:45 | return try parse(lhs, path: rhs, decode: decodeArray(catchNull(T.decode))) |
| Operators.swift:50 | return try parse(lhs, path: rhs, decode: catchNull(decodeArray(catchNull(T.decode)))) |
| Operators.swift:50 | return try parse(lhs, path: rhs, decode: catchNull(decodeArray(catchNull(T.decode)))) |
| Operators.swift:62 | return try parse(lhs, path: rhs, decode: catchNull(decodeDictionary(String.decode, elementDecodeClosure: T.decode))) |
| Operators.swift:67 | return try parse(lhs, path: rhs, decode: catchNull(decodeDictionary(K.decode, elementDecodeClosure: {$0}))) |
| Operators.swift:91 | return try parseAndAcceptMissingKey(lhs, path: rhs, decode: decodeArray(catchNull(T.decode))) |
| Parse.swift:38 | return try catchAndRethrow(json, path) { try catchNull(decode)(object) } |
<T>(decodeClosure: (AnyObject) throws -> T) -> (AnyObject) throws -> T? {
0130 return { json in
0131 if json is NSNull {
0132 return nil
0133 } else {
0134 return try decodeClosure(json)
0135 }
0136 }
0137 }
0138
0139 private func parse| Operators.swift:18 | return try parse(lhs, path: rhs, decode: T.decode) |
| Operators.swift:23 | return try parse(lhs, path: rhs, decode: { $0 }) |
| Operators.swift:28 | return try parse(lhs, path: rhs, decode: catchNull(T.decode)) |
| Operators.swift:35 | return try parse(lhs, path: rhs, decode: decodeArray(T.decode)) |
| Operators.swift:40 | return try parse(lhs, path: rhs, decode: catchNull(decodeArray(T.decode))) |
| Operators.swift:45 | return try parse(lhs, path: rhs, decode: decodeArray(catchNull(T.decode))) |
| Operators.swift:50 | return try parse(lhs, path: rhs, decode: catchNull(decodeArray(catchNull(T.decode)))) |
| Operators.swift:57 | return try parse(lhs, path: rhs, decode: decodeDictionary(String.decode, elementDecodeClosure: T.decode)) |
| Operators.swift:62 | return try parse(lhs, path: rhs, decode: catchNull(decodeDictionary(String.decode, elementDecodeClosure: T.decode))) |
| Operators.swift:67 | return try parse(lhs, path: rhs, decode: catchNull(decodeDictionary(K.decode, elementDecodeClosure: {$0}))) |
<T>(json: AnyObject, path: String, decode: (AnyObject throws -> T)) throws -> T {
0140 return try parse(json, path: path.toJSONPathArray(), decode: decode)
0141 }
0142
0143 private func parseAndAcceptMissingKey| Operators.swift:74 | return try parseAndAcceptMissingKey(lhs, path: rhs, decode: { $0 }) |
| Operators.swift:79 | return try parseAndAcceptMissingKey(lhs, path: rhs, decode: T.decode) |
| Operators.swift:86 | return try parseAndAcceptMissingKey(lhs, path: rhs, decode: decodeArray(T.decode)) |
| Operators.swift:91 | return try parseAndAcceptMissingKey(lhs, path: rhs, decode: decodeArray(catchNull(T.decode))) |
| Operators.swift:98 | return try parseAndAcceptMissingKey(lhs, path: rhs, decode: decodeDictionary(String.decode, elementDecodeClosure: T.decode) ) |
| Operators.swift:103 | return try parseAndAcceptMissingKey(lhs, path: rhs, decode: decodeDictionary(K.decode, elementDecodeClosure: {$0})) |
<T>(json: AnyObject, path: String, decode: (AnyObject throws -> T)) throws -> T? {
0144 return try parseAndAcceptMissingKey(json, path: path.toJSONPathArray(), decode: decode)
0145 }
0146
0147