0001 // 0002 // decode.swift 0003 // Himotoki 0004 // 0005 // Created by Syo Ikeda on 5/19/15. 0006 // Copyright (c) 2015 Syo Ikeda. All rights reserved. 0007 // 0008 0009 /// - Throws: DecodeError 0010 public func decode<T: Decodable where T.DecodedType == T>(object: AnyObject) throws -> T { 0011 let extractor = Extractor(object) 0012 return try T.decode(extractor) 0013 } 0014 0015 /// - Throws: DecodeError 0016 public func decode<T: Decodable where T.DecodedType == T>(object: AnyObject, rootKeyPath: KeyPath) throws -> T { 0017 return try decode(object) <| rootKeyPath 0018 } 0019 0020 /// - Throws: DecodeError 0021 public func decodeArray
decode.swift:17 return try decode(object) <| rootKeyPathdecode.swift:26 return try array.map(decode)decode.swift:31 return try decode(object) <|| rootKeyPathdecode.swift:42 result[key] = try decode(value) as Tdecode.swift:49 return try decode(object) <|-| rootKeyPathExtractor.swift:36 return try decode(rawValue)<T: Decodable where T.DecodedType == T>(object: AnyObject) throws -> [T] { 0022 guard let array = object as? [AnyObject] else { 0023 throw typeMismatch("Array", actual: object, keyPath: nil) 0024 } 0025 0026 return try array.map(decode) 0027 } 0028 0029 /// - Throws: DecodeError 0030 public func decodeArray<T: Decodable where T.DecodedType == T>(object: AnyObject, rootKeyPath: KeyPath) throws -> [T] { 0031 return try decode(object) <|| rootKeyPath 0032 } 0033 0034 /// - Throws: DecodeError 0035 public func decodeDictionary
Extractor.swift:64 return try rawValue(keyPath).map(decodeArray)<T: Decodable where T.DecodedType == T>(object: AnyObject) throws -> [String: T] { 0036 guard let dictionary = object as? [String: AnyObject] else { 0037 throw typeMismatch("Dictionary", actual: object, keyPath: nil) 0038 } 0039 0040 var result: [String: T] = [:] 0041 try dictionary.forEach { key, value in 0042 result[key] = try decode(value) as T 0043 } 0044 return result 0045 } 0046 0047 /// - Throws: DecodeError 0048 public func decodeDictionary<T: Decodable where T.DecodedType == T>(object: AnyObject, rootKeyPath: KeyPath) throws -> [String: T] { 0049 return try decode(object) <|-| rootKeyPath 0050 } 0051
Extractor.swift:78 return try rawValue(keyPath).map(decodeDictionary)