0001 // 0002 // Extractor.swift 0003 // Himotoki 0004 // 0005 // Created by Syo Ikeda on 5/2/15. 0006 // Copyright (c) 2015 Syo Ikeda. All rights reserved. 0007 // 0008 0009 import Foundation 0010 0011 public struct Extractor{ 0012 public let rawValue
Decodable.swift:13 static func decode(e: Extractor) throws -> DecodedTypedecode.swift:11 let extractor = Extractor(object)Extractor.swift:82 extension Extractor: Decodable {Extractor.swift:83 public static func decode(e: Extractor) throws -> Extractor {Extractor.swift:83 public static func decode(e: Extractor) throws -> Extractor {Extractor.swift:88 extension Extractor: CustomStringConvertible {NSNumber.swift:12 public static func decode(e: Extractor) throws -> NSNumber {NSNumber.swift:18 public static func decode(e: Extractor) throws -> UInt {NSNumber.swift:24 public static func decode(e: Extractor) throws -> Int8 {NSNumber.swift:30 public static func decode(e: Extractor) throws -> UInt8 {NSNumber.swift:36 public static func decode(e: Extractor) throws -> Int16 {NSNumber.swift:42 public static func decode(e: Extractor) throws -> UInt16 {NSNumber.swift:48 public static func decode(e: Extractor) throws -> Int32 {NSNumber.swift:54 public static func decode(e: Extractor) throws -> UInt32 {NSNumber.swift:60 public static func decode(e: Extractor) throws -> Int64 {NSNumber.swift:66 public static func decode(e: Extractor) throws -> UInt64 {Operators.swift:17 public func <| <T: Decodable where T.DecodedType == T>(e: Extractor, keyPath: KeyPath) throws -> T {Operators.swift:22 public func <|? <T: Decodable where T.DecodedType == T>(e: Extractor, keyPath: KeyPath) throws -> T? {Operators.swift:27 public func <|| <T: Decodable where T.DecodedType == T>(e: Extractor, keyPath: KeyPath) throws -> [T] {Operators.swift:32 public func <||? <T: Decodable where T.DecodedType == T>(e: Extractor, keyPath: KeyPath) throws -> [T]? {Operators.swift:37 public func <|-| <T: Decodable where T.DecodedType == T>(e: Extractor, keyPath: KeyPath) throws -> [String: T] {Operators.swift:42 public func <|-|? <T: Decodable where T.DecodedType == T>(e: Extractor, keyPath: KeyPath) throws -> [String: T]? {RawRepresentable.swift:10 static func decode(e: Extractor) throws -> Self {StandardLib.swift:10 public static func decode(e: Extractor) throws -> String {StandardLib.swift:16 public static func decode(e: Extractor) throws -> Int {StandardLib.swift:22 public static func decode(e: Extractor) throws -> Double {StandardLib.swift:28 public static func decode(e: Extractor) throws -> Float {StandardLib.swift:34 public static func decode(e: Extractor) throws -> Bool {StandardLib.swift:39 internal func castOrFail<T>(e: Extractor) throws -> T {: AnyObject 0013 private let isDictionary
Extractor.swift:16 self.rawValue = rawValueExtractor.swift:22 throw typeMismatch("Dictionary", actual: rawValue, keyPath: keyPath)Extractor.swift:26 return valueFor(components, rawValue)Extractor.swift:90 return "Extractor(\(rawValue))"StandardLib.swift:40 let rawValue = e.rawValue: Bool 0014 0015 internal init
Extractor.swift:17 self.isDictionary = rawValue is NSDictionaryExtractor.swift:21 guard isDictionary else {(_ rawValue: AnyObject) { 0016 self.rawValue = rawValue 0017 self.isDictionary = rawValue is NSDictionary 0018 } 0019 0020 private func rawValue
decode.swift:11 let extractor = Extractor(object)(keyPath: KeyPath) throws -> AnyObject? { 0021 guard isDictionary else { 0022 throw typeMismatch("Dictionary", actual: rawValue, keyPath: keyPath) 0023 } 0024 0025 let components = ArraySlice(keyPath.components) 0026 return valueFor(components, rawValue) 0027 } 0028 0029 /// - Throws: DecodeError 0030 public func value
Extractor.swift:31 guard let rawValue = try rawValue(keyPath) else {Extractor.swift:64 return try rawValue(keyPath).map(decodeArray)Extractor.swift:78 return try rawValue(keyPath).map(decodeDictionary)<T: Decodable where T.DecodedType == T>(keyPath: KeyPath) throws -> T { 0031 guard let rawValue = try rawValue(keyPath) else { 0032 throw DecodeError.MissingKeyPath(keyPath) 0033 } 0034 0035 do { 0036 return try decode(rawValue) 0037 } catch let DecodeError.MissingKeyPath(missing) { 0038 throw DecodeError.MissingKeyPath(keyPath + missing) 0039 } catch let DecodeError.TypeMismatch(expected, actual, _) { 0040 throw DecodeError.TypeMismatch(expected: expected, actual: actual, keyPath: keyPath) 0041 } 0042 } 0043 0044 /// - Throws: DecodeError 0045 public func valueOptional
Extractor.swift:47 return try value(keyPath) as TOperators.swift:18 return try e.value(keyPath)<T: Decodable where T.DecodedType == T>(keyPath: KeyPath) throws -> T? { 0046 do { 0047 return try value(keyPath) as T 0048 } catch let DecodeError.MissingKeyPath(missing) where missing == keyPath { 0049 return nil 0050 } 0051 } 0052 0053 /// - Throws: DecodeError 0054 public func array
Operators.swift:23 return try e.valueOptional(keyPath)<T: Decodable where T.DecodedType == T>(keyPath: KeyPath) throws -> [T] { 0055 guard let array: [T] = try arrayOptional(keyPath) else { 0056 throw DecodeError.MissingKeyPath(keyPath) 0057 } 0058 0059 return array 0060 } 0061 0062 /// - Throws: DecodeError 0063 public func arrayOptional
Operators.swift:28 return try e.array(keyPath)<T: Decodable where T.DecodedType == T>(keyPath: KeyPath) throws -> [T]? { 0064 return try rawValue(keyPath).map(decodeArray) 0065 } 0066 0067 /// - Throws: DecodeError 0068 public func dictionary
Extractor.swift:55 guard let array: [T] = try arrayOptional(keyPath) else {Operators.swift:33 return try e.arrayOptional(keyPath)<T: Decodable where T.DecodedType == T>(keyPath: KeyPath) throws -> [String: T] { 0069 guard let dictionary: [String: T] = try dictionaryOptional(keyPath) else { 0070 throw DecodeError.MissingKeyPath(keyPath) 0071 } 0072 0073 return dictionary 0074 } 0075 0076 /// - Throws: DecodeError 0077 public func dictionaryOptional
Operators.swift:38 return try e.dictionary(keyPath)<T: Decodable where T.DecodedType == T>(keyPath: KeyPath) throws -> [String: T]? { 0078 return try rawValue(keyPath).map(decodeDictionary) 0079 } 0080 } 0081 0082 extension Extractor: Decodable { 0083 public static func decode(e: Extractor) throws -> Extractor { 0084 return e 0085 } 0086 } 0087 0088 extension Extractor: CustomStringConvertible { 0089 public var description: String { 0090 return "Extractor(\(rawValue))" 0091 } 0092 } 0093 0094 // Implement it as a tail recursive function. 0095 // 0096 // `ArraySlice` is used for performance optimization. 0097 // See https://gist.github.com/norio-nomura/d9ec7212f2cfde3fb662. 0098 private func valueFor
Extractor.swift:69 guard let dictionary: [String: T] = try dictionaryOptional(keyPath) else {Operators.swift:43 return try e.dictionaryOptional(keyPath)<C: CollectionType where C.Generator.Element == String, C.SubSequence == C>(keyPathComponents: C, _ object: AnyObject) -> AnyObject? { 0099 #if os(Linux) 0100 guard let 0101 first = keyPathComponents.first, 0102 let nativeDict = object as? [String: AnyObject], 0103 case let nested? = nativeDict[first] where !(nested is NSNull) else 0104 { 0105 return nil 0106 } 0107 #else 0108 guard let first = keyPathComponents.first, case let nested?? = object[first] where !(nested is NSNull) else { 0109 return nil 0110 } 0111 #endif 0112 0113 if keyPathComponents.count == 1 { 0114 return nested 0115 } 0116 0117 let tail = keyPathComponents.dropFirst() 0118 return valueFor(tail, nested) 0119 } 0120
Extractor.swift:26 return valueFor(components, rawValue)Extractor.swift:118 return valueFor(tail, nested)