0001 // 0002 // Decodable.swift 0003 // Decodable 0004 // 0005 // Created by Johannes Lund on 2015-07-07. 0006 // Copyright © 2015 anviking. All rights reserved. 0007 // 0008 0009 import Foundation 0010 0011 public protocol Decodable{ 0012 static func decode
Castable.swift:11 public protocol Castable: Decodable {}NSValueCastable.swift:21 public protocol NSValueCastable: Decodable {}Operators.swift:17 public func => <T: Decodable>(lhs: AnyObject, rhs: String) throws -> T {Operators.swift:27 public func => <T: Decodable>(lhs: AnyObject, rhs: String) throws -> T? {Operators.swift:34 public func => <T: Decodable>(lhs: AnyObject, rhs: String) throws -> [T] {Operators.swift:39 public func => <T: Decodable>(lhs: AnyObject, rhs: String) throws -> [T]? {Operators.swift:44 public func => <T: Decodable>(lhs: AnyObject, rhs: String) throws -> [T?] {Operators.swift:49 public func => <T: Decodable>(lhs: AnyObject, rhs: String) throws -> [T?]? {Operators.swift:56 public func => <T: Decodable>(lhs: AnyObject, rhs: String) throws -> [String: T] {Operators.swift:61 public func => <T: Decodable>(lhs: AnyObject, rhs: String) throws -> [String: T]? {Operators.swift:66 public func => <K: Decodable>(lhs: AnyObject, rhs: String) throws -> [K: AnyObject]? {Operators.swift:78 public func =>? <T: Decodable>(lhs: AnyObject, rhs: String) throws -> T? {Operators.swift:85 public func =>? <T: Decodable>(lhs: AnyObject, rhs: String) throws -> [T]? {Operators.swift:90 public func =>? <T: Decodable>(lhs: AnyObject, rhs: String) throws -> [T?]? {Operators.swift:97 public func =>? <T: Decodable>(lhs: AnyObject, rhs: String) throws -> [String: T]? {Operators.swift:102 public func =>? <K: Decodable>(lhs: AnyObject, rhs: String) throws -> [K: AnyObject]? {(json: AnyObject) throws -> Self 0013 } 0014 0015 extension NSDictionary { 0016 public static func decode
Decodable.swift:35 return try decodeDictionary(Key.decode, elementDecodeClosure: Value.decode)(json: j)Decodable.swift:35 return try decodeDictionary(Key.decode, elementDecodeClosure: Value.decode)(json: j)Decodable.swift:42 return try decodeArray { try? Element.decode($0) }(json: j).flatMap {$0}Decodable.swift:44 return try decodeArray(Element.decode)(json: j)Operators.swift:18 return try parse(lhs, path: rhs, decode: T.decode)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})))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}))RawRepresentableDecodable.swift:18 let rawValue = try RawValue.decode(json)(j: AnyObject) throws -> NSDictionary { 0017 guard let result = j as? NSDictionary else { 0018 throw TypeMismatchError(expectedType: self, receivedType: j.dynamicType, object: j) 0019 } 0020 return result 0021 } 0022 } 0023 0024 extension NSArray { 0025 public static func decode
Decodable.swift:63 for (key, value) in try NSDictionary.decode(json) {Parse.swift:14 let currentDict = try NSDictionary.decode(a.object)(j: AnyObject) throws -> NSArray { 0026 guard let result = j as? NSArray else { 0027 throw TypeMismatchError(expectedType: self, receivedType: j.dynamicType, object: j) 0028 } 0029 return result 0030 } 0031 } 0032 0033 extension Dictionary where Key: Decodable, Value: Decodable { 0034 public static func decode(j: AnyObject) throws -> Dictionary { 0035 return try decodeDictionary(Key.decode, elementDecodeClosure: Value.decode)(json: j) 0036 } 0037 } 0038 0039 extension Array where Element: Decodable { 0040 public static func decode(j: AnyObject, ignoreInvalidObjects: Bool = false) throws -> [Element] { 0041 if ignoreInvalidObjects { 0042 return try decodeArray { try? Element.decode($0) }(json: j).flatMap {$0} 0043 } else { 0044 return try decodeArray(Element.decode)(json: j) 0045 } 0046 } 0047 } 0048 0049 0050 // MARK: Helpers 0051 0052 /// Designed to be used with parse(json, path, decodeClosure) as the decodeClosure. Thats why it's curried and a "top-level" function instead of a function in an array extension. For everyday use, prefer using [T].decode(json) instead. 0053 public func decodeArray
Decodable.swift:55 return try NSArray.decode(json).map { try elementDecodeClosure($0) }<T>(elementDecodeClosure: AnyObject throws -> T) -> (json: AnyObject) throws -> [T] { 0054 return { json in 0055 return try NSArray.decode(json).map { try elementDecodeClosure($0) } 0056 } 0057 } 0058 0059 /// Designed to be used with parse(json, path, decodeClosure) as the decodeClosure. Thats why it's curried. For everyday use, prefer using [K: V].decode(json) instead (declared in Decodable.swift). 0060 public func decodeDictionary
Decodable.swift:42 return try decodeArray { try? Element.decode($0) }(json: j).flatMap {$0}Decodable.swift:44 return try decodeArray(Element.decode)(json: j)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: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)))<K,V>(keyDecodeClosure: AnyObject throws -> K, elementDecodeClosure: AnyObject throws -> V) -> (json: AnyObject) throws -> [K: V] { 0061 return { json in 0062 var dict = [K: V]() 0063 for (key, value) in try NSDictionary.decode(json) { 0064 try dict[keyDecodeClosure(key)] = elementDecodeClosure(value) 0065 } 0066 return dict 0067 } 0068 } 0069
Decodable.swift:35 return try decodeDictionary(Key.decode, elementDecodeClosure: Value.decode)(json: j)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})))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}))