0001    //
0002    //  JSONError.swift
0003    //  PMJSON
0004    //
0005    //  Created by Kevin Ballard on 11/9/15.
0006    //  Copyright © 2016 Postmates.
0007    //
0008    //  Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
0009    //  http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
0010    //  <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
0011    //  option. This file may not be copied, modified, or distributed
0012    //  except according to those terms.
0013    //
0014    
0015    // MARK: JSONError
0016    
0017    /// Errors thrown by the JSON `get*` or `to*` accessor families.
0018    public enum JSONError
DecimalNumber.swift:52
            default: throw JSONError.MissingOrInvalidType(path: nil, expected: .Required(.Number), actual: .forValue(self))
DecimalNumber.swift:64
            default: throw JSONError.MissingOrInvalidType(path: nil, expected: .Required(.Number), actual: .forValue(self))
DecimalNumber.swift:76
                throw JSONError.MissingOrInvalidType(path: nil, expected: .Required(.Number), actual: .forValue(self))
DecimalNumber.swift:90
            else { throw JSONError.MissingOrInvalidType(path: nil, expected: .Optional(.Number), actual: .forValue(self)) }
JSONError.swift:45
    private func withPrefix(prefix: String) -> JSONError {
JSONError.swift:107
        guard let b = bool else { throw JSONError.MissingOrInvalidType(path: nil, expected: .Required(.Bool), actual: .forValue(self)) }
JSONError.swift:117
        else { throw JSONError.MissingOrInvalidType(path: nil, expected: .Optional(.Bool), actual: .forValue(self)) }
JSONError.swift:124
        guard let str = string else { throw JSONError.MissingOrInvalidType(path: nil, expected: .Required(.String), actual: .forValue(self)) }
JSONError.swift:134
        else { throw JSONError.MissingOrInvalidType(path: nil, expected: .Optional(.String), actual: .forValue(self)) }
JSONError.swift:141
        guard let val = int64 else { throw JSONError.MissingOrInvalidType(path: nil, expected: .Required(.Number), actual: .forValue(self)) }
JSONError.swift:151
        else { throw JSONError.MissingOrInvalidType(path: nil, expected: .Optional(.Number), actual: .forValue(self)) }
JSONError.swift:159
        guard let val = int64 else { throw JSONError.MissingOrInvalidType(path: nil, expected: .Required(.Number), actual: .forValue(self)) }
JSONError.swift:161
        guard Swift.Int64(truncated) == val else { throw JSONError.OutOfRangeInt64(path: nil, value: val, expected: Int.self) }
JSONError.swift:172
            guard Swift.Int64(truncated) == val else { throw JSONError.OutOfRangeInt64(path: nil, value: val, expected: Int.self) }
JSONError.swift:175
        else { throw JSONError.MissingOrInvalidType(path: nil, expected: .Optional(.Number), actual: .forValue(self)) }
JSONError.swift:182
        guard let val = double else { throw JSONError.MissingOrInvalidType(path: nil, expected: .Required(.Number), actual: .forValue(self)) }
JSONError.swift:192
        else { throw JSONError.MissingOrInvalidType(path: nil, expected: .Optional(.Number), actual: .forValue(self)) }
JSONError.swift:199
        guard let dict = object else { throw JSONError.MissingOrInvalidType(path: nil, expected: .Required(.Object), actual: .forValue(self)) }
JSONError.swift:209
        else { throw JSONError.MissingOrInvalidType(path: nil, expected: .Optional(.Object), actual: .forValue(self)) }
JSONError.swift:216
        guard let ary = array else { throw JSONError.MissingOrInvalidType(path: nil, expected: .Required(.Array), actual: .forValue(self)) }
JSONError.swift:226
        else { throw JSONError.MissingOrInvalidType(path: nil, expected: .Optional(.Array), actual: .forValue(self)) }
JSONError.swift:245
    private func toStringMaybeNil(expected: JSONError.ExpectedType) throws -> Swift.String? {
JSONError.swift:252
        default: throw JSONError.MissingOrInvalidType(path: nil, expected: expected, actual: .forValue(self))
JSONError.swift:265
            throw JSONError.MissingOrInvalidType(path: nil, expected: .Required(.Number), actual: .Null)
JSONError.swift:281
    private func toInt64MaybeNil(expected: JSONError.ExpectedType) throws -> Swift.Int64? {
JSONError.swift:287
                throw JSONError.OutOfRangeDouble(path: nil, value: d, expected: Swift.Int64.self)
JSONError.swift:295
                    throw JSONError.OutOfRangeDouble(path: nil, value: d, expected: Swift.Int64.self)
JSONError.swift:304
        throw JSONError.MissingOrInvalidType(path: nil, expected: expected, actual: .forValue(self))
JSONError.swift:317
        guard Swift.Int64(truncated) == val else { throw JSONError.OutOfRangeInt64(path: nil, value: val, expected: Int.self) }
JSONError.swift:331
        guard Swift.Int64(truncated) == val else { throw JSONError.OutOfRangeInt64(path: nil, value: val, expected: Int.self) }
JSONError.swift:341
            throw JSONError.MissingOrInvalidType(path: nil, expected: .Required(.Number), actual: .Null)
JSONError.swift:354
    private func toDoubleMaybeNil(expected: JSONError.ExpectedType) throws -> Swift.Double? {
JSONError.swift:360
        default: throw JSONError.MissingOrInvalidType(path: nil, expected: expected, actual: .forValue(self))
JSONError.swift:1293
internal func getRequired(dict: JSONObject, key: String, type: JSONError.JSONType) throws -> JSON {
JSONError.swift:1294
    guard let value = dict[key] else { throw JSONError.MissingOrInvalidType(path: key, expected: .Required(type), actual: nil) }
JSONError.swift:1298
internal func getRequired(ary: JSONArray, index: Int, type: JSONError.JSONType) throws -> JSON {
JSONError.swift:1299
    guard let value = ary[safe: index] else { throw JSONError.MissingOrInvalidType(path: "[\(index)]", expected: .Required(type), actual: nil) }
JSONError.swift:1307
    } catch let error as JSONError {
JSONError.swift:1316
    } catch let error as JSONError {
: ErrorType, CustomStringConvertible { 0019 /// Thrown when a given path is missing or has the wrong type. 0020 /// - Parameter path: The path of the key that caused the error. 0021 /// - Parameter expected: The type that was expected at this path. 0022 /// - Parameter actual: The type of the value found at the path, or `nil` if there was no value. 0023 case MissingOrInvalidType
DecimalNumber.swift:52
            default: throw JSONError.MissingOrInvalidType(path: nil, expected: .Required(.Number), actual: .forValue(self))
DecimalNumber.swift:64
            default: throw JSONError.MissingOrInvalidType(path: nil, expected: .Required(.Number), actual: .forValue(self))
DecimalNumber.swift:76
                throw JSONError.MissingOrInvalidType(path: nil, expected: .Required(.Number), actual: .forValue(self))
DecimalNumber.swift:90
            else { throw JSONError.MissingOrInvalidType(path: nil, expected: .Optional(.Number), actual: .forValue(self)) }
JSONError.swift:39
        case let .MissingOrInvalidType(path, expected, actual): return "\(path.map({$0+": "}) ?? "")expected \(expected), found \(actual?.description ?? "missing value")"
JSONError.swift:55
        case let .MissingOrInvalidType(path, expected, actual):
JSONError.swift:56
            return .MissingOrInvalidType(path: prefixPath(path, with: prefix), expected: expected, actual: actual)
JSONError.swift:107
        guard let b = bool else { throw JSONError.MissingOrInvalidType(path: nil, expected: .Required(.Bool), actual: .forValue(self)) }
JSONError.swift:117
        else { throw JSONError.MissingOrInvalidType(path: nil, expected: .Optional(.Bool), actual: .forValue(self)) }
JSONError.swift:124
        guard let str = string else { throw JSONError.MissingOrInvalidType(path: nil, expected: .Required(.String), actual: .forValue(self)) }
JSONError.swift:134
        else { throw JSONError.MissingOrInvalidType(path: nil, expected: .Optional(.String), actual: .forValue(self)) }
JSONError.swift:141
        guard let val = int64 else { throw JSONError.MissingOrInvalidType(path: nil, expected: .Required(.Number), actual: .forValue(self)) }
JSONError.swift:151
        else { throw JSONError.MissingOrInvalidType(path: nil, expected: .Optional(.Number), actual: .forValue(self)) }
JSONError.swift:159
        guard let val = int64 else { throw JSONError.MissingOrInvalidType(path: nil, expected: .Required(.Number), actual: .forValue(self)) }
JSONError.swift:175
        else { throw JSONError.MissingOrInvalidType(path: nil, expected: .Optional(.Number), actual: .forValue(self)) }
JSONError.swift:182
        guard let val = double else { throw JSONError.MissingOrInvalidType(path: nil, expected: .Required(.Number), actual: .forValue(self)) }
JSONError.swift:192
        else { throw JSONError.MissingOrInvalidType(path: nil, expected: .Optional(.Number), actual: .forValue(self)) }
JSONError.swift:199
        guard let dict = object else { throw JSONError.MissingOrInvalidType(path: nil, expected: .Required(.Object), actual: .forValue(self)) }
JSONError.swift:209
        else { throw JSONError.MissingOrInvalidType(path: nil, expected: .Optional(.Object), actual: .forValue(self)) }
JSONError.swift:216
        guard let ary = array else { throw JSONError.MissingOrInvalidType(path: nil, expected: .Required(.Array), actual: .forValue(self)) }
JSONError.swift:226
        else { throw JSONError.MissingOrInvalidType(path: nil, expected: .Optional(.Array), actual: .forValue(self)) }
JSONError.swift:252
        default: throw JSONError.MissingOrInvalidType(path: nil, expected: expected, actual: .forValue(self))
JSONError.swift:265
            throw JSONError.MissingOrInvalidType(path: nil, expected: .Required(.Number), actual: .Null)
JSONError.swift:304
        throw JSONError.MissingOrInvalidType(path: nil, expected: expected, actual: .forValue(self))
JSONError.swift:341
            throw JSONError.MissingOrInvalidType(path: nil, expected: .Required(.Number), actual: .Null)
JSONError.swift:360
        default: throw JSONError.MissingOrInvalidType(path: nil, expected: expected, actual: .forValue(self))
JSONError.swift:1294
    guard let value = dict[key] else { throw JSONError.MissingOrInvalidType(path: key, expected: .Required(type), actual: nil) }
JSONError.swift:1299
    guard let value = ary[safe: index] else { throw JSONError.MissingOrInvalidType(path: "[\(index)]", expected: .Required(type), actual: nil) }
(path: String?, expected: ExpectedType, actual: JSONType?) 0024 /// Thrown when an integral value is coerced to a smaller type (e.g. `Int64` to `Int`) and the 0025 /// value doesn't fit in the smaller type. 0026 /// - Parameter path: The path of the value that cuased the error. 0027 /// - Parameter value: The actual value at that path. 0028 /// - Parameter expected: The type that the value doesn't fit in, e.g. `Int.self`. 0029 case OutOfRangeInt64
JSONError.swift:40
        case let .OutOfRangeInt64(path, value, expected): return "\(path.map({$0+": "}) ?? "")value \(value) cannot be coerced to type \(expected)"
JSONError.swift:57
        case let .OutOfRangeInt64(path, value, expected):
JSONError.swift:58
            return .OutOfRangeInt64(path: prefixPath(path, with: prefix), value: value, expected: expected)
JSONError.swift:161
        guard Swift.Int64(truncated) == val else { throw JSONError.OutOfRangeInt64(path: nil, value: val, expected: Int.self) }
JSONError.swift:172
            guard Swift.Int64(truncated) == val else { throw JSONError.OutOfRangeInt64(path: nil, value: val, expected: Int.self) }
JSONError.swift:317
        guard Swift.Int64(truncated) == val else { throw JSONError.OutOfRangeInt64(path: nil, value: val, expected: Int.self) }
JSONError.swift:331
        guard Swift.Int64(truncated) == val else { throw JSONError.OutOfRangeInt64(path: nil, value: val, expected: Int.self) }
(path: String?, value: Int64, expected: Any.Type) 0030 /// Thrown when a floating-point value is coerced to a smaller type (e.g. `Double` to `Int`) 0031 /// and the value doesn't fit in the smaller type. 0032 /// - Parameter path: The path of the value that cuased the error. 0033 /// - Parameter value: The actual value at that path. 0034 /// - Parameter expected: The type that the value doesn't fit in, e.g. `Int.self`. 0035 case OutOfRangeDouble
JSONError.swift:41
        case let .OutOfRangeDouble(path, value, expected): return "\(path.map({$0+": "}) ?? "")value \(value) cannot be coerced to type \(expected)"
JSONError.swift:59
        case let .OutOfRangeDouble(path, value, expected):
JSONError.swift:60
            return .OutOfRangeDouble(path: prefixPath(path, with: prefix), value: value, expected: expected)
JSONError.swift:287
                throw JSONError.OutOfRangeDouble(path: nil, value: d, expected: Swift.Int64.self)
JSONError.swift:295
                    throw JSONError.OutOfRangeDouble(path: nil, value: d, expected: Swift.Int64.self)
(path: String?, value: Double, expected: Any.Type) 0036 0037 public var description: String { 0038 switch self { 0039 case let .MissingOrInvalidType(path, expected, actual): return "\(path.map({$0+": "}) ?? "")expected \(expected), found \(actual?.description ?? "missing value")" 0040 case let .OutOfRangeInt64(path, value, expected): return "\(path.map({$0+": "}) ?? "")value \(value) cannot be coerced to type \(expected)" 0041 case let .OutOfRangeDouble(path, value, expected): return "\(path.map({$0+": "}) ?? "")value \(value) cannot be coerced to type \(expected)" 0042 } 0043 } 0044 0045 private func withPrefix
JSONError.swift:1308
        throw error.withPrefix(key)
JSONError.swift:1317
        throw error.withPrefix("[\(index)]")
(prefix: String) -> JSONError { 0046 func prefixPath(path: String?, with prefix: String) -> String { 0047 guard let path = path where !path.isEmpty else { return prefix } 0048 if path.unicodeScalars.first == "[" { 0049 return prefix + path 0050 } else { 0051 return "\(prefix).\(path)" 0052 } 0053 } 0054 switch self { 0055 case let .MissingOrInvalidType(path, expected, actual): 0056 return .MissingOrInvalidType(path: prefixPath(path, with: prefix), expected: expected, actual: actual) 0057 case let .OutOfRangeInt64(path, value, expected): 0058 return .OutOfRangeInt64(path: prefixPath(path, with: prefix), value: value, expected: expected) 0059 case let .OutOfRangeDouble(path, value, expected): 0060 return .OutOfRangeDouble(path: prefixPath(path, with: prefix), value: value, expected: expected) 0061 } 0062 } 0063 0064 public enum ExpectedType
JSONError.swift:23
    case MissingOrInvalidType(path: String?, expected: ExpectedType, actual: JSONType?)
JSONError.swift:245
    private func toStringMaybeNil(expected: JSONError.ExpectedType) throws -> Swift.String? {
JSONError.swift:281
    private func toInt64MaybeNil(expected: JSONError.ExpectedType) throws -> Swift.Int64? {
JSONError.swift:354
    private func toDoubleMaybeNil(expected: JSONError.ExpectedType) throws -> Swift.Double? {
: CustomStringConvertible { 0065 case Required
DecimalNumber.swift:52
            default: throw JSONError.MissingOrInvalidType(path: nil, expected: .Required(.Number), actual: .forValue(self))
DecimalNumber.swift:64
            default: throw JSONError.MissingOrInvalidType(path: nil, expected: .Required(.Number), actual: .forValue(self))
DecimalNumber.swift:76
                throw JSONError.MissingOrInvalidType(path: nil, expected: .Required(.Number), actual: .forValue(self))
JSONError.swift:70
            case .Required(let type): return type.description
JSONError.swift:107
        guard let b = bool else { throw JSONError.MissingOrInvalidType(path: nil, expected: .Required(.Bool), actual: .forValue(self)) }
JSONError.swift:124
        guard let str = string else { throw JSONError.MissingOrInvalidType(path: nil, expected: .Required(.String), actual: .forValue(self)) }
JSONError.swift:141
        guard let val = int64 else { throw JSONError.MissingOrInvalidType(path: nil, expected: .Required(.Number), actual: .forValue(self)) }
JSONError.swift:159
        guard let val = int64 else { throw JSONError.MissingOrInvalidType(path: nil, expected: .Required(.Number), actual: .forValue(self)) }
JSONError.swift:182
        guard let val = double else { throw JSONError.MissingOrInvalidType(path: nil, expected: .Required(.Number), actual: .forValue(self)) }
JSONError.swift:199
        guard let dict = object else { throw JSONError.MissingOrInvalidType(path: nil, expected: .Required(.Object), actual: .forValue(self)) }
JSONError.swift:216
        guard let ary = array else { throw JSONError.MissingOrInvalidType(path: nil, expected: .Required(.Array), actual: .forValue(self)) }
JSONError.swift:235
        return try toStringMaybeNil(.Required(.String)) ?? "null"
JSONError.swift:264
        guard let val = try toInt64MaybeNil(.Required(.Number)) else {
JSONError.swift:265
            throw JSONError.MissingOrInvalidType(path: nil, expected: .Required(.Number), actual: .Null)
JSONError.swift:340
        guard let val = try toDoubleMaybeNil(.Required(.Number)) else {
JSONError.swift:341
            throw JSONError.MissingOrInvalidType(path: nil, expected: .Required(.Number), actual: .Null)
JSONError.swift:1294
    guard let value = dict[key] else { throw JSONError.MissingOrInvalidType(path: key, expected: .Required(type), actual: nil) }
JSONError.swift:1299
    guard let value = ary[safe: index] else { throw JSONError.MissingOrInvalidType(path: "[\(index)]", expected: .Required(type), actual: nil) }
(JSONType) 0066 case Optional
DecimalNumber.swift:90
            else { throw JSONError.MissingOrInvalidType(path: nil, expected: .Optional(.Number), actual: .forValue(self)) }
JSONError.swift:71
            case .Optional(let type): return "\(type) or null"
JSONError.swift:117
        else { throw JSONError.MissingOrInvalidType(path: nil, expected: .Optional(.Bool), actual: .forValue(self)) }
JSONError.swift:134
        else { throw JSONError.MissingOrInvalidType(path: nil, expected: .Optional(.String), actual: .forValue(self)) }
JSONError.swift:151
        else { throw JSONError.MissingOrInvalidType(path: nil, expected: .Optional(.Number), actual: .forValue(self)) }
JSONError.swift:175
        else { throw JSONError.MissingOrInvalidType(path: nil, expected: .Optional(.Number), actual: .forValue(self)) }
JSONError.swift:192
        else { throw JSONError.MissingOrInvalidType(path: nil, expected: .Optional(.Number), actual: .forValue(self)) }
JSONError.swift:209
        else { throw JSONError.MissingOrInvalidType(path: nil, expected: .Optional(.Object), actual: .forValue(self)) }
JSONError.swift:226
        else { throw JSONError.MissingOrInvalidType(path: nil, expected: .Optional(.Array), actual: .forValue(self)) }
JSONError.swift:242
        return try toStringMaybeNil(.Optional(.String))
JSONError.swift:278
        return try toInt64MaybeNil(.Optional(.Number))
JSONError.swift:351
        return try toDoubleMaybeNil(.Optional(.Number))
(JSONType) 0067 0068 public var description: String { 0069 switch self { 0070 case .Required(let type): return type.description 0071 case .Optional(let type): return "\(type) or null" 0072 } 0073 } 0074 } 0075 0076 public enum JSONType
JSONError.swift:23
    case MissingOrInvalidType(path: String?, expected: ExpectedType, actual: JSONType?)
JSONError.swift:65
        case Required(JSONType)
JSONError.swift:66
        case Optional(JSONType)
JSONError.swift:84
        internal static func forValue(value: JSON) -> JSONType {
JSONError.swift:1293
internal func getRequired(dict: JSONObject, key: String, type: JSONError.JSONType) throws -> JSON {
JSONError.swift:1298
internal func getRequired(ary: JSONArray, index: Int, type: JSONError.JSONType) throws -> JSON {
: String, CustomStringConvertible { 0077 case Null
JSONError.swift:86
            case .Null: return .Null
JSONError.swift:265
            throw JSONError.MissingOrInvalidType(path: nil, expected: .Required(.Number), actual: .Null)
JSONError.swift:341
            throw JSONError.MissingOrInvalidType(path: nil, expected: .Required(.Number), actual: .Null)
= "null" 0078 case Bool
JSONError.swift:87
            case .Bool: return .Bool
JSONError.swift:107
        guard let b = bool else { throw JSONError.MissingOrInvalidType(path: nil, expected: .Required(.Bool), actual: .forValue(self)) }
JSONError.swift:117
        else { throw JSONError.MissingOrInvalidType(path: nil, expected: .Optional(.Bool), actual: .forValue(self)) }
JSONError.swift:669
        let value = try getRequired(ary, index: index, type: .Bool)
= "bool" 0079 case String
JSONError.swift:88
            case .String: return .String
JSONError.swift:124
        guard let str = string else { throw JSONError.MissingOrInvalidType(path: nil, expected: .Required(.String), actual: .forValue(self)) }
JSONError.swift:134
        else { throw JSONError.MissingOrInvalidType(path: nil, expected: .Optional(.String), actual: .forValue(self)) }
JSONError.swift:235
        return try toStringMaybeNil(.Required(.String)) ?? "null"
JSONError.swift:242
        return try toStringMaybeNil(.Optional(.String))
JSONError.swift:374
        let value = try getRequired(dict, key: key, type: .String)
JSONError.swift:395
        let value = try getRequired(dict, key: key, type: .String)
JSONError.swift:573
        let value = try getRequired(dict, key: key, type: .String)
JSONError.swift:690
        let value = try getRequired(ary, index: index, type: .String)
JSONError.swift:873
        let value = try getRequired(ary, index: index, type: .String)
JSONError.swift:974
        let value = try getRequired(self, key: key, type: .String)
JSONError.swift:992
        let value = try getRequired(self, key: key, type: .String)
JSONError.swift:1155
        let value = try getRequired(self, key: key, type: .String)
= "string" 0080 case Number
DecimalNumber.swift:52
            default: throw JSONError.MissingOrInvalidType(path: nil, expected: .Required(.Number), actual: .forValue(self))
DecimalNumber.swift:64
            default: throw JSONError.MissingOrInvalidType(path: nil, expected: .Required(.Number), actual: .forValue(self))
DecimalNumber.swift:76
                throw JSONError.MissingOrInvalidType(path: nil, expected: .Required(.Number), actual: .forValue(self))
DecimalNumber.swift:90
            else { throw JSONError.MissingOrInvalidType(path: nil, expected: .Optional(.Number), actual: .forValue(self)) }
DecimalNumber.swift:104
            let value = try getRequired(dict, key: key, type: .Number)
DecimalNumber.swift:127
            let value = try getRequired(dict, key: key, type: .Number)
DecimalNumber.swift:153
            let value = try getRequired(array, index: index, type: .Number)
DecimalNumber.swift:175
            let value = try getRequired(array, index: index, type: .Number)
DecimalNumber.swift:200
            let value = try getRequired(self, key: key, type: .Number)
DecimalNumber.swift:221
            let value = try getRequired(self, key: key, type: .Number)
JSONError.swift:89
            case .Int64, .Double: return .Number
JSONError.swift:141
        guard let val = int64 else { throw JSONError.MissingOrInvalidType(path: nil, expected: .Required(.Number), actual: .forValue(self)) }
JSONError.swift:151
        else { throw JSONError.MissingOrInvalidType(path: nil, expected: .Optional(.Number), actual: .forValue(self)) }
JSONError.swift:159
        guard let val = int64 else { throw JSONError.MissingOrInvalidType(path: nil, expected: .Required(.Number), actual: .forValue(self)) }
JSONError.swift:175
        else { throw JSONError.MissingOrInvalidType(path: nil, expected: .Optional(.Number), actual: .forValue(self)) }
JSONError.swift:182
        guard let val = double else { throw JSONError.MissingOrInvalidType(path: nil, expected: .Required(.Number), actual: .forValue(self)) }
JSONError.swift:192
        else { throw JSONError.MissingOrInvalidType(path: nil, expected: .Optional(.Number), actual: .forValue(self)) }
JSONError.swift:264
        guard let val = try toInt64MaybeNil(.Required(.Number)) else {
JSONError.swift:265
            throw JSONError.MissingOrInvalidType(path: nil, expected: .Required(.Number), actual: .Null)
JSONError.swift:278
        return try toInt64MaybeNil(.Optional(.Number))
JSONError.swift:340
        guard let val = try toDoubleMaybeNil(.Required(.Number)) else {
JSONError.swift:341
            throw JSONError.MissingOrInvalidType(path: nil, expected: .Required(.Number), actual: .Null)
JSONError.swift:351
        return try toDoubleMaybeNil(.Optional(.Number))
JSONError.swift:416
        let value = try getRequired(dict, key: key, type: .Number)
JSONError.swift:438
        let value = try getRequired(dict, key: key, type: .Number)
JSONError.swift:460
        let value = try getRequired(dict, key: key, type: .Number)
JSONError.swift:596
        let value = try getRequired(dict, key: key, type: .Number)
JSONError.swift:620
        let value = try getRequired(dict, key: key, type: .Number)
JSONError.swift:644
        let value = try getRequired(dict, key: key, type: .Number)
JSONError.swift:711
        let value = try getRequired(ary, index: index, type: .Number)
JSONError.swift:733
        let value = try getRequired(ary, index: index, type: .Number)
JSONError.swift:755
        let value = try getRequired(ary, index: index, type: .Number)
JSONError.swift:897
        let value = try getRequired(ary, index: index, type: .Number)
JSONError.swift:923
        let value = try getRequired(ary, index: index, type: .Number)
JSONError.swift:949
        let value = try getRequired(ary, index: index, type: .Number)
JSONError.swift:1010
        let value = try getRequired(self, key: key, type: .Number)
JSONError.swift:1029
        let value = try getRequired(self, key: key, type: .Number)
JSONError.swift:1048
        let value = try getRequired(self, key: key, type: .Number)
JSONError.swift:1176
        let value = try getRequired(self, key: key, type: .Number)
JSONError.swift:1198
        let value = try getRequired(self, key: key, type: .Number)
JSONError.swift:1220
        let value = try getRequired(self, key: key, type: .Number)
= "number" 0081 case Object
JSONError.swift:90
            case .Object: return .Object
JSONError.swift:199
        guard let dict = object else { throw JSONError.MissingOrInvalidType(path: nil, expected: .Required(.Object), actual: .forValue(self)) }
JSONError.swift:209
        else { throw JSONError.MissingOrInvalidType(path: nil, expected: .Optional(.Object), actual: .forValue(self)) }
JSONError.swift:800
        let value = try getRequired(ary, index: index, type: .Object)
JSONError.swift:1090
        let value = try getRequired(self, key: key, type: .Object)
= "object" 0082 case Array
JSONError.swift:91
            case .Array: return .Array
JSONError.swift:216
        guard let ary = array else { throw JSONError.MissingOrInvalidType(path: nil, expected: .Required(.Array), actual: .forValue(self)) }
JSONError.swift:226
        else { throw JSONError.MissingOrInvalidType(path: nil, expected: .Optional(.Array), actual: .forValue(self)) }
JSONError.swift:547
        let value = try getRequired(dict, key: key, type: .Array)
JSONError.swift:847
        let value = try getRequired(ary, index: index, type: .Array)
JSONError.swift:1132
        let value = try getRequired(self, key: key, type: .Array)
= "array" 0083 0084 internal static func forValue
DecimalNumber.swift:52
            default: throw JSONError.MissingOrInvalidType(path: nil, expected: .Required(.Number), actual: .forValue(self))
DecimalNumber.swift:64
            default: throw JSONError.MissingOrInvalidType(path: nil, expected: .Required(.Number), actual: .forValue(self))
DecimalNumber.swift:76
                throw JSONError.MissingOrInvalidType(path: nil, expected: .Required(.Number), actual: .forValue(self))
DecimalNumber.swift:90
            else { throw JSONError.MissingOrInvalidType(path: nil, expected: .Optional(.Number), actual: .forValue(self)) }
JSONError.swift:107
        guard let b = bool else { throw JSONError.MissingOrInvalidType(path: nil, expected: .Required(.Bool), actual: .forValue(self)) }
JSONError.swift:117
        else { throw JSONError.MissingOrInvalidType(path: nil, expected: .Optional(.Bool), actual: .forValue(self)) }
JSONError.swift:124
        guard let str = string else { throw JSONError.MissingOrInvalidType(path: nil, expected: .Required(.String), actual: .forValue(self)) }
JSONError.swift:134
        else { throw JSONError.MissingOrInvalidType(path: nil, expected: .Optional(.String), actual: .forValue(self)) }
JSONError.swift:141
        guard let val = int64 else { throw JSONError.MissingOrInvalidType(path: nil, expected: .Required(.Number), actual: .forValue(self)) }
JSONError.swift:151
        else { throw JSONError.MissingOrInvalidType(path: nil, expected: .Optional(.Number), actual: .forValue(self)) }
JSONError.swift:159
        guard let val = int64 else { throw JSONError.MissingOrInvalidType(path: nil, expected: .Required(.Number), actual: .forValue(self)) }
JSONError.swift:175
        else { throw JSONError.MissingOrInvalidType(path: nil, expected: .Optional(.Number), actual: .forValue(self)) }
JSONError.swift:182
        guard let val = double else { throw JSONError.MissingOrInvalidType(path: nil, expected: .Required(.Number), actual: .forValue(self)) }
JSONError.swift:192
        else { throw JSONError.MissingOrInvalidType(path: nil, expected: .Optional(.Number), actual: .forValue(self)) }
JSONError.swift:199
        guard let dict = object else { throw JSONError.MissingOrInvalidType(path: nil, expected: .Required(.Object), actual: .forValue(self)) }
JSONError.swift:209
        else { throw JSONError.MissingOrInvalidType(path: nil, expected: .Optional(.Object), actual: .forValue(self)) }
JSONError.swift:216
        guard let ary = array else { throw JSONError.MissingOrInvalidType(path: nil, expected: .Required(.Array), actual: .forValue(self)) }
JSONError.swift:226
        else { throw JSONError.MissingOrInvalidType(path: nil, expected: .Optional(.Array), actual: .forValue(self)) }
JSONError.swift:252
        default: throw JSONError.MissingOrInvalidType(path: nil, expected: expected, actual: .forValue(self))
JSONError.swift:304
        throw JSONError.MissingOrInvalidType(path: nil, expected: expected, actual: .forValue(self))
JSONError.swift:360
        default: throw JSONError.MissingOrInvalidType(path: nil, expected: expected, actual: .forValue(self))
(value: JSON) -> JSONType { 0085 switch value { 0086 case .Null: return .Null 0087 case .Bool: return .Bool 0088 case .String: return .String 0089 case .Int64, .Double: return .Number 0090 case .Object: return .Object 0091 case .Array: return .Array 0092 } 0093 } 0094 0095 public var description
JSONError.swift:39
        case let .MissingOrInvalidType(path, expected, actual): return "\(path.map({$0+": "}) ?? "")expected \(expected), found \(actual?.description ?? "missing value")"
JSONError.swift:70
            case .Required(let type): return type.description
: Swift.String { 0096 return rawValue 0097 } 0098 } 0099 } 0100 0101 // MARK: - Basic accessors 0102 public extension JSON { 0103 /// Returns the bool value if the receiver is a bool. 0104 /// - Returns: A `Bool` value. 0105 /// - Throws: `JSONError` if the receiver is the wrong type. 0106 func getBool
JSONError.swift:375
        return try scoped(key) { try value.getBool() }
JSONError.swift:670
        return try scoped(index) { try value.getBool() }
JSONError.swift:975
        return try scoped(key) { try value.getBool() }
() throws -> Swift.Bool { 0107 guard let b = bool else { throw JSONError.MissingOrInvalidType(path: nil, expected: .Required(.Bool), actual: .forValue(self)) } 0108 return b 0109 } 0110 0111 /// Returns the bool value if the receiver is a bool. 0112 /// - Returns: A `Bool` value, or `nil` if the receiver is `null`. 0113 /// - Throws: `JSONError` if the receiver is the wrong type. 0114 func getBoolOrNil
JSONError.swift:385
        return try scoped(key) { try value.getBoolOrNil() }
JSONError.swift:680
        return try scoped(index) { try value.getBoolOrNil() }
JSONError.swift:984
        return try scoped(key) { try value.getBoolOrNil() }
() throws -> Swift.Bool? { 0115 if let b = bool { return b } 0116 else if isNull { return nil } 0117 else { throw JSONError.MissingOrInvalidType(path: nil, expected: .Optional(.Bool), actual: .forValue(self)) } 0118 } 0119 0120 /// Returns the string value if the receiver is a string. 0121 /// - Returns: A `String` value. 0122 /// - Throws: `JSONError` if the receiver is the wrong type. 0123 func getString
JSONError.swift:396
        return try scoped(key) { try value.getString() }
JSONError.swift:691
        return try scoped(index) { try value.getString() }
JSONError.swift:993
        return try scoped(key) { try value.getString() }
() throws -> Swift.String { 0124 guard let str = string else { throw JSONError.MissingOrInvalidType(path: nil, expected: .Required(.String), actual: .forValue(self)) } 0125 return str 0126 } 0127 0128 /// Returns the string value if the receiver is a string. 0129 /// - Returns: A `String` value, or `nil` if the receiver is `null`. 0130 /// - Throws: `JSONError` if the receiver is the wrong type. 0131 func getStringOrNil
JSONError.swift:406
        return try scoped(key) { try value.getStringOrNil() }
JSONError.swift:701
        return try scoped(index) { try value.getStringOrNil() }
JSONError.swift:1002
        return try scoped(key) { try value.getStringOrNil() }
() throws -> Swift.String? { 0132 if let str = string { return str } 0133 else if isNull { return nil } 0134 else { throw JSONError.MissingOrInvalidType(path: nil, expected: .Optional(.String), actual: .forValue(self)) } 0135 } 0136 0137 /// Returns the 64-bit integral value if the receiver is a number. 0138 /// - Returns: An `Int64` value. 0139 /// - Throws: `JSONError` if the receiver is the wrong type. 0140 func getInt64
JSONError.swift:417
        return try scoped(key) { try value.getInt64() }
JSONError.swift:712
        return try scoped(index) { try value.getInt64() }
JSONError.swift:1011
        return try scoped(key) { try value.getInt64() }
() throws -> Swift.Int64 { 0141 guard let val = int64 else { throw JSONError.MissingOrInvalidType(path: nil, expected: .Required(.Number), actual: .forValue(self)) } 0142 return val 0143 } 0144 0145 /// Returns the 64-bit integral value value if the receiver is a number. 0146 /// - Returns: An `Int64` value, or `nil` if the receiver is `null`. 0147 /// - Throws: `JSONError` if the receiver is the wrong type. 0148 func getInt64OrNil
JSONError.swift:427
        return try scoped(key) { try value.getInt64OrNil() }
JSONError.swift:722
        return try scoped(index) { try value.getInt64OrNil() }
JSONError.swift:1020
        return try scoped(key) { try value.getInt64OrNil() }
() throws -> Swift.Int64? { 0149 if let val = int64 { return val } 0150 else if isNull { return nil } 0151 else { throw JSONError.MissingOrInvalidType(path: nil, expected: .Optional(.Number), actual: .forValue(self)) } 0152 } 0153 0154 /// Returns the integral value if the receiver is a number. 0155 /// - Returns: An `Int` value. 0156 /// - Throws: `JSONError` if the receiver is the wrong type, or if the 64-bit integral value 0157 /// is too large to fit in an `Int`. 0158 func getInt
JSONError.swift:439
        return try scoped(key) { try value.getInt() }
JSONError.swift:734
        return try scoped(index) { try value.getInt() }
JSONError.swift:1030
        return try scoped(key) { try value.getInt() }
() throws -> Int { 0159 guard let val = int64 else { throw JSONError.MissingOrInvalidType(path: nil, expected: .Required(.Number), actual: .forValue(self)) } 0160 let truncated = Int(truncatingBitPattern: val) 0161 guard Swift.Int64(truncated) == val else { throw JSONError.OutOfRangeInt64(path: nil, value: val, expected: Int.self) } 0162 return truncated 0163 } 0164 0165 /// Returns the integral value if the receiver is a number. 0166 /// - Returns: An `Int` value, or `nil` if the receiver is `null`. 0167 /// - Throws: `JSONError` if the receiver is the wrong type, or if the 64-bit integral value 0168 /// is too large to fit in an `Int`. 0169 func getIntOrNil
JSONError.swift:450
        return try scoped(key) { try value.getIntOrNil() }
JSONError.swift:745
        return try scoped(index) { try value.getIntOrNil() }
JSONError.swift:1040
        return try scoped(key) { try value.getIntOrNil() }
() throws -> Int? { 0170 if let val = int64 { 0171 let truncated = Int(truncatingBitPattern: val) 0172 guard Swift.Int64(truncated) == val else { throw JSONError.OutOfRangeInt64(path: nil, value: val, expected: Int.self) } 0173 return truncated 0174 } else if isNull { return nil } 0175 else { throw JSONError.MissingOrInvalidType(path: nil, expected: .Optional(.Number), actual: .forValue(self)) } 0176 } 0177 0178 /// Returns the double value if the receiver is a number. 0179 /// - Returns: A `Double` value. 0180 /// - Throws: `JSONError` if the receiver is the wrong type. 0181 func getDouble
JSONError.swift:461
        return try scoped(key) { try value.getDouble() }
JSONError.swift:756
        return try scoped(index) { try value.getDouble() }
JSONError.swift:1049
        return try scoped(key) { try value.getDouble() }
() throws -> Swift.Double { 0182 guard let val = double else { throw JSONError.MissingOrInvalidType(path: nil, expected: .Required(.Number), actual: .forValue(self)) } 0183 return val 0184 } 0185 0186 /// Returns the double value if the receiver is a number. 0187 /// - Returns: A `Double` value, or `nil` if the receiver is `null`. 0188 /// - Throws: `JSONError` if the receiver is the wrong type. 0189 func getDoubleOrNil
JSONError.swift:471
        return try scoped(key) { try value.getDoubleOrNil() }
JSONError.swift:766
        return try scoped(index) { try value.getDoubleOrNil() }
JSONError.swift:1058
        return try scoped(key) { try value.getDoubleOrNil() }
() throws -> Swift.Double? { 0190 if let val = double { return val } 0191 else if isNull { return nil } 0192 else { throw JSONError.MissingOrInvalidType(path: nil, expected: .Optional(.Number), actual: .forValue(self)) } 0193 } 0194 0195 /// Returns the object value if the receiver is an object. 0196 /// - Returns: An object value. 0197 /// - Throws: `JSONError` if the receiver is the wrong type. 0198 func getObject
DecimalNumber.swift:103
            let dict = try getObject()
DecimalNumber.swift:114
            let dict = try getObject()
DecimalNumber.swift:126
            let dict = try getObject()
DecimalNumber.swift:137
            let dict = try getObject()
JSONError.swift:373
        let dict = try getObject()
JSONError.swift:383
        let dict = try getObject()
JSONError.swift:394
        let dict = try getObject()
JSONError.swift:404
        let dict = try getObject()
JSONError.swift:415
        let dict = try getObject()
JSONError.swift:425
        let dict = try getObject()
JSONError.swift:437
        let dict = try getObject()
JSONError.swift:448
        let dict = try getObject()
JSONError.swift:459
        let dict = try getObject()
JSONError.swift:469
        let dict = try getObject()
JSONError.swift:504
        return try getObject().getObject(key, transform)
JSONError.swift:514
        return try getObject().getObjectOrNil(key, transform)
JSONError.swift:546
        let dict = try getObject()
JSONError.swift:558
        let dict = try getObject()
JSONError.swift:572
        let dict = try getObject()
JSONError.swift:583
        let dict = try getObject()
JSONError.swift:595
        let dict = try getObject()
JSONError.swift:607
        let dict = try getObject()
JSONError.swift:619
        let dict = try getObject()
JSONError.swift:631
        let dict = try getObject()
JSONError.swift:643
        let dict = try getObject()
JSONError.swift:654
        let dict = try getObject()
JSONError.swift:801
        return try scoped(index) { try f(value.getObject()) }
JSONError.swift:1091
        return try scoped(key) { try f(value.getObject()) }
() throws -> JSONObject { 0199 guard let dict = object else { throw JSONError.MissingOrInvalidType(path: nil, expected: .Required(.Object), actual: .forValue(self)) } 0200 return dict 0201 } 0202 0203 /// Returns the object value if the receiver is an object. 0204 /// - Returns: An object value, or `nil` if the receiver is `null`. 0205 /// - Throws: `JSONError` if the receiver is the wrong type. 0206 func getObjectOrNil
JSONError.swift:813
        return try scoped(index) { try value.getObjectOrNil().flatMap(f) }
JSONError.swift:1101
        return try scoped(key) { try value.getObjectOrNil().flatMap(f) }
() throws -> JSONObject? { 0207 if let dict = object { return dict } 0208 else if isNull { return nil } 0209 else { throw JSONError.MissingOrInvalidType(path: nil, expected: .Optional(.Object), actual: .forValue(self)) } 0210 } 0211 0212 /// Returns the array value if the receiver is an array. 0213 /// - Returns: An array value. 0214 /// - Throws: `JSONError` if the receiver is the wrong type. 0215 func getArray
DecimalNumber.swift:152
            let array = try getArray()
DecimalNumber.swift:162
            let array = try getArray()
DecimalNumber.swift:174
            let array = try getArray()
DecimalNumber.swift:185
            let array = try getArray()
JSONError.swift:548
        return try scoped(key) { try transform(value.getArray()) }
JSONError.swift:668
        let ary = try getArray()
JSONError.swift:678
        let ary = try getArray()
JSONError.swift:689
        let ary = try getArray()
JSONError.swift:699
        let ary = try getArray()
JSONError.swift:710
        let ary = try getArray()
JSONError.swift:720
        let ary = try getArray()
JSONError.swift:732
        let ary = try getArray()
JSONError.swift:743
        let ary = try getArray()
JSONError.swift:754
        let ary = try getArray()
JSONError.swift:764
        let ary = try getArray()
JSONError.swift:799
        let ary = try getArray()
JSONError.swift:811
        let ary = try getArray()
JSONError.swift:846
        let ary = try getArray()
JSONError.swift:848
        return try scoped(index) { try f(value.getArray()) }
JSONError.swift:858
        let ary = try getArray()
JSONError.swift:872
        let ary = try getArray()
JSONError.swift:883
        let ary = try getArray()
JSONError.swift:896
        let ary = try getArray()
JSONError.swift:909
        let ary = try getArray()
JSONError.swift:922
        let ary = try getArray()
JSONError.swift:935
        let ary = try getArray()
JSONError.swift:948
        let ary = try getArray()
JSONError.swift:960
        let ary = try getArray()
JSONError.swift:1133
        return try scoped(key) { try f(value.getArray()) }
() throws -> JSONArray { 0216 guard let ary = array else { throw JSONError.MissingOrInvalidType(path: nil, expected: .Required(.Array), actual: .forValue(self)) } 0217 return ary 0218 } 0219 0220 /// Returns the array value if the receiver is an array. 0221 /// - Returns: An array value, or `nil` if the receiver is `null`. 0222 /// - Throws: `JSONError` if the receiver is the wrong type. 0223 func getArrayOrNil
JSONError.swift:560
        return try scoped(key) { try value.getArrayOrNil().flatMap(transform) }
JSONError.swift:860
        return try scoped(index) { try value.getArrayOrNil().flatMap(f) }
JSONError.swift:1143
        return try scoped(key) { try value.getArrayOrNil().flatMap(f) }
() throws -> JSONArray? { 0224 if let ary = array { return ary } 0225 else if isNull { return nil } 0226 else { throw JSONError.MissingOrInvalidType(path: nil, expected: .Optional(.Array), actual: .forValue(self)) } 0227 } 0228 } 0229 0230 public extension JSON { 0231 /// Returns the receiver coerced to a string value. 0232 /// - Returns: A `String` value. 0233 /// - Throws: `JSONError` if the receiver is an object or array. 0234 func toString
Accessors.swift:148
        return try? toString()
JSONError.swift:574
        return try scoped(key) { try value.toString() }
JSONError.swift:874
        return try scoped(index) { try value.toString() }
JSONError.swift:1156
        return try scoped(key) { try value.toString() }
() throws -> Swift.String { 0235 return try toStringMaybeNil(.Required(.String)) ?? "null" 0236 } 0237 0238 /// Returns the receiver coerced to a string value. 0239 /// - Returns: A `String` value, or `nil` if the receiver is `null`. 0240 /// - Throws: `JSONError` if the receiver is an object or array. 0241 func toStringOrNil
JSONError.swift:585
        return try scoped(key) { try value.toStringOrNil() }
JSONError.swift:885
        return try scoped(index) { try value.toStringOrNil() }
JSONError.swift:1166
        return try scoped(key) { try value.toStringOrNil() }
() throws -> Swift.String? { 0242 return try toStringMaybeNil(.Optional(.String)) 0243 } 0244 0245 private func toStringMaybeNil
JSONError.swift:235
        return try toStringMaybeNil(.Required(.String)) ?? "null"
JSONError.swift:242
        return try toStringMaybeNil(.Optional(.String))
(expected: JSONError.ExpectedType) throws -> Swift.String? { 0246 switch self { 0247 case .String(let s): return s 0248 case .Null: return nil 0249 case .Bool(let b): return Swift.String(b) 0250 case .Int64(let i): return Swift.String(i) 0251 case .Double(let d): return Swift.String(d) 0252 default: throw JSONError.MissingOrInvalidType(path: nil, expected: expected, actual: .forValue(self)) 0253 } 0254 } 0255 0256 /// Returns the receiver coerced to a 64-bit integral value. 0257 /// If the receiver is a floating-point value, the value will be truncated 0258 /// to an integer. 0259 /// - Returns: An `Int64` value`. 0260 /// - Throws: `JSONError` if the receiver is `null`, a boolean, an object, 0261 /// an array, a string that cannot be coerced to a 64-bit integral value, 0262 /// or a floating-point value that does not fit in 64 bits. 0263 func toInt64
Accessors.swift:157
        return try? toInt64()
JSONError.swift:315
        let val = try toInt64()
JSONError.swift:597
        return try scoped(key) { try value.toInt64() }
JSONError.swift:898
        return try scoped(index) { try value.toInt64() }
JSONError.swift:1177
        return try scoped(key) { try value.toInt64() }
() throws -> Swift.Int64 { 0264 guard let val = try toInt64MaybeNil(.Required(.Number)) else { 0265 throw JSONError.MissingOrInvalidType(path: nil, expected: .Required(.Number), actual: .Null) 0266 } 0267 return val 0268 } 0269 0270 /// Returns the receiver coerced to a 64-bit integral value. 0271 /// If the receiver is a floating-point value, the value will be truncated 0272 /// to an integer. 0273 /// - Returns: An `Int64` value`, or `nil` if the receiver is `null`. 0274 /// - Throws: `JSONError` if the receiver is a boolean, an object, an array, 0275 /// a string that cannot be coerced to a 64-bit integral value, 0276 /// or a floating-point value that does not fit in 64 bits. 0277 func toInt64OrNil
JSONError.swift:329
        guard let val = try toInt64OrNil() else { return nil }
JSONError.swift:609
        return try scoped(key) { try value.toInt64OrNil() }
JSONError.swift:911
        return try scoped(index) { try value.toInt64OrNil() }
JSONError.swift:1188
        return try scoped(key) { try value.toInt64OrNil() }
() throws -> Swift.Int64? { 0278 return try toInt64MaybeNil(.Optional(.Number)) 0279 } 0280 0281 private func toInt64MaybeNil
JSONError.swift:264
        guard let val = try toInt64MaybeNil(.Required(.Number)) else {
JSONError.swift:278
        return try toInt64MaybeNil(.Optional(.Number))
(expected: JSONError.ExpectedType) throws -> Swift.Int64? { 0282 switch self { 0283 case .Int64(let i): 0284 return i 0285 case .Double(let d): 0286 guard let val = convertDoubleToInt64(d) else { 0287 throw JSONError.OutOfRangeDouble(path: nil, value: d, expected: Swift.Int64.self) 0288 } 0289 return val 0290 case .String(let s): 0291 if let i = Swift.Int64(s, radix: 10) { 0292 return i 0293 } else if let d = Swift.Double(s) { 0294 guard let val = convertDoubleToInt64(d) else { 0295 throw JSONError.OutOfRangeDouble(path: nil, value: d, expected: Swift.Int64.self) 0296 } 0297 return val 0298 } 0299 case .Null: 0300 return nil 0301 default: 0302 break 0303 } 0304 throw JSONError.MissingOrInvalidType(path: nil, expected: expected, actual: .forValue(self)) 0305 } 0306 0307 /// Returns the receiver coerced to an integral value. 0308 /// If the receiver is a floating-point value, the value will be truncated 0309 /// to an integer. 0310 /// - Returns: An `Int` value`. 0311 /// - Throws: `JSONError` if the receiver is `null`, a boolean, an object, 0312 /// an array, a string that cannot be coerced to an integral value, 0313 /// or a floating-point value that does not fit in an `Int`. 0314 func toInt
Accessors.swift:166
        return try? toInt()
JSONError.swift:621
        return try scoped(key) { try value.toInt() }
JSONError.swift:924
        return try scoped(index) { try value.toInt() }
JSONError.swift:1199
        return try scoped(key) { try value.toInt() }
() throws -> Int { 0315 let val = try toInt64() 0316 let truncated = Int(truncatingBitPattern: val) 0317 guard Swift.Int64(truncated) == val else { throw JSONError.OutOfRangeInt64(path: nil, value: val, expected: Int.self) } 0318 return truncated 0319 } 0320 0321 /// Returns the receiver coerced to an integral value. 0322 /// If the receiver is a floating-point value, the value will be truncated 0323 /// to an integer. 0324 /// - Returns: An `Int` value`, or `nil` if the receiver is `null`. 0325 /// - Throws: `JSONError` if the receiver is a boolean, an object, 0326 /// an array, a string that cannot be coerced to an integral value, 0327 /// or a floating-point value that does not fit in an `Int`. 0328 func toIntOrNil
JSONError.swift:633
        return try scoped(key) { try value.toIntOrNil() }
JSONError.swift:937
        return try scoped(index) { try value.toIntOrNil() }
JSONError.swift:1210
        return try scoped(key) { try value.toIntOrNil() }
() throws -> Int? { 0329 guard let val = try toInt64OrNil() else { return nil } 0330 let truncated = Int(truncatingBitPattern: val) 0331 guard Swift.Int64(truncated) == val else { throw JSONError.OutOfRangeInt64(path: nil, value: val, expected: Int.self) } 0332 return truncated 0333 } 0334 0335 /// Returns the receiver coerced to a `Double`. 0336 /// - Returns: A `Double` value. 0337 /// - Throws: `JSONError` if the receiver is `null`, a boolean, an object, an array, 0338 /// or a string that cannot be coerced to a floating-point value. 0339 func toDouble
Accessors.swift:173
        return try? toDouble()
JSONError.swift:645
        return try scoped(key) { try value.toDouble() }
JSONError.swift:950
        return try scoped(index) { try value.toDouble() }
JSONError.swift:1221
        return try scoped(key) { try value.toDouble() }
() throws -> Swift.Double { 0340 guard let val = try toDoubleMaybeNil(.Required(.Number)) else { 0341 throw JSONError.MissingOrInvalidType(path: nil, expected: .Required(.Number), actual: .Null) 0342 } 0343 return val 0344 } 0345 0346 /// Returns the receiver coerced to a `Double`. 0347 /// - Returns: A `Double` value, or `nil` if the receiver is `null`. 0348 /// - Throws: `JSONError` if the receiver is a boolean, an object, an array, 0349 /// or a string that cannot be coerced to a floating-point value. 0350 func toDoubleOrNil
JSONError.swift:656
        return try scoped(key) { try value.toDoubleOrNil() }
JSONError.swift:962
        return try scoped(index) { try value.toDoubleOrNil() }
JSONError.swift:1231
        return try scoped(key) { try value.toDoubleOrNil() }
() throws -> Swift.Double? { 0351 return try toDoubleMaybeNil(.Optional(.Number)) 0352 } 0353 0354 private func toDoubleMaybeNil
JSONError.swift:340
        guard let val = try toDoubleMaybeNil(.Required(.Number)) else {
JSONError.swift:351
        return try toDoubleMaybeNil(.Optional(.Number))
(expected: JSONError.ExpectedType) throws -> Swift.Double? { 0355 switch self { 0356 case .Int64(let i): return Swift.Double(i) 0357 case .Double(let d): return d 0358 case .String(let s): return Swift.Double(s) 0359 case .Null: return nil 0360 default: throw JSONError.MissingOrInvalidType(path: nil, expected: expected, actual: .forValue(self)) 0361 } 0362 } 0363 } 0364 0365 // MARK: - Keyed accessors 0366 public extension JSON { 0367 /// Subscripts the receiver with `key` and returns the result. 0368 /// - Parameter key: The key that's used to subscript the receiver. 0369 /// - Returns: A `Bool` value. 0370 /// - Throws: `JSONError` if the key doesn't exist or the value is the wrong type, or if 0371 /// the receiver is not an object. 0372 func getBool(key: Swift.String) throws -> Swift.Bool { 0373 let dict = try getObject() 0374 let value = try getRequired(dict, key: key, type: .String) 0375 return try scoped(key) { try value.getBool() } 0376 } 0377 0378 /// Subscripts the receiver with `key` and returns the result. 0379 /// - Parameter key: The key that's used to subscript the receiver. 0380 /// - Returns: A `Bool` value, or `nil` if the key doesn't exist or the value is `null`. 0381 /// - Throws: `JSONError` if the value has the wrong type, or if the receiver is not an object. 0382 func getBoolOrNil(key: Swift.String) throws -> Swift.Bool? { 0383 let dict = try getObject() 0384 guard let value = dict[key] else { return nil } 0385 return try scoped(key) { try value.getBoolOrNil() } 0386 } 0387 0388 /// Subscripts the receiver with `key` and returns the result. 0389 /// - Parameter key: The key that's used to subscript the receiver. 0390 /// - Returns: A `String` value. 0391 /// - Throws: `JSONError` if the key doesn't exist or the value is the wrong type, or if 0392 /// the receiver is not an object. 0393 func getString(key: Swift.String) throws -> Swift.String { 0394 let dict = try getObject() 0395 let value = try getRequired(dict, key: key, type: .String) 0396 return try scoped(key) { try value.getString() } 0397 } 0398 0399 /// Subscripts the receiver with `key` and returns the result. 0400 /// - Parameter key: The key that's used to subscript the receiver. 0401 /// - Returns: A `String` value, or `nil` if the key doesn't exist or the value is `null`. 0402 /// - Throws: `JSONError` if the value has the wrong type, or if the receiver is not an object. 0403 func getStringOrNil(key: Swift.String) throws -> Swift.String? { 0404 let dict = try getObject() 0405 guard let value = dict[key] else { return nil } 0406 return try scoped(key) { try value.getStringOrNil() } 0407 } 0408 0409 /// Subscripts the receiver with `key` and returns the result. 0410 /// - Parameter key: The key that's used to subscript the receiver. 0411 /// - Returns: An `Int64` value. 0412 /// - Throws: `JSONError` if the key doesn't exist or the value is the wrong type, or if 0413 /// the receiver is not an object. 0414 func getInt64(key: Swift.String) throws -> Swift.Int64 { 0415 let dict = try getObject() 0416 let value = try getRequired(dict, key: key, type: .Number) 0417 return try scoped(key) { try value.getInt64() } 0418 } 0419 0420 /// Subscripts the receiver with `key` and returns the result. 0421 /// - Parameter key: The key that's used to subscript the receiver. 0422 /// - Returns: An `Int64` value, or `nil` if the key doesn't exist or the value is `null`. 0423 /// - Throws: `JSONError` if the value has the wrong type, or if the receiver is not an object. 0424 func getInt64OrNil(key: Swift.String) throws -> Swift.Int64? { 0425 let dict = try getObject() 0426 guard let value = dict[key] else { return nil } 0427 return try scoped(key) { try value.getInt64OrNil() } 0428 } 0429 0430 /// Subscripts the receiver with `key` and returns the result. 0431 /// - Parameter key: The key that's used to subscript the receiver. 0432 /// - Returns: An `Int` value. 0433 /// - Throws: `JSONError` if the key doesn't exist or the value is the wrong type, 0434 /// or if the 64-bit integral value is too large to fit in an `Int`, or if 0435 /// the receiver is not an object. 0436 func getInt(key: Swift.String) throws -> Int { 0437 let dict = try getObject() 0438 let value = try getRequired(dict, key: key, type: .Number) 0439 return try scoped(key) { try value.getInt() } 0440 } 0441 0442 /// Subscripts the receiver with `key` and returns the result. 0443 /// - Parameter key: The key that's used to subscript the receiver. 0444 /// - Returns: An `Int` value, or `nil` if the key doesn't exist or the value is `null`. 0445 /// - Throws: `JSONError` if the value has the wrong type, or if the 64-bit integral 0446 /// value is too large to fit in an `Int`, or if the receiver is not an object. 0447 func getIntOrNil(key: Swift.String) throws -> Int? { 0448 let dict = try getObject() 0449 guard let value = dict[key] else { return nil } 0450 return try scoped(key) { try value.getIntOrNil() } 0451 } 0452 0453 /// Subscripts the receiver with `key` and returns the result. 0454 /// - Parameter key: The key that's used to subscript the receiver. 0455 /// - Returns: A `Double` value. 0456 /// - Throws: `JSONError` if the key doesn't exist or the value is the wrong type, or if 0457 /// the receiver is not an object. 0458 func getDouble(key: Swift.String) throws -> Swift.Double { 0459 let dict = try getObject() 0460 let value = try getRequired(dict, key: key, type: .Number) 0461 return try scoped(key) { try value.getDouble() } 0462 } 0463 0464 /// Subscripts the receiver with `key` and returns the result. 0465 /// - Parameter key: The key that's used to subscript the receiver. 0466 /// - Returns: A `Double` value, or `nil` if the key doesn't exist or the value is `null`. 0467 /// - Throws: `JSONError` if the value has the wrong type, or if the receiver is not an object. 0468 func getDoubleOrNil(key: Swift.String) throws -> Swift.Double? { 0469 let dict = try getObject() 0470 guard let value = dict[key] else { return nil } 0471 return try scoped(key) { try value.getDoubleOrNil() } 0472 } 0473 0474 /// Subscripts the receiver with `key` and returns the result. 0475 /// - Note: Use `getObject(_:_:)` when using throwing accessors on the resulting 0476 /// object value to produce better errors. 0477 /// - Parameter key: The key that's used to subscript the receiver. 0478 /// - Returns: An object value. 0479 /// - Throws: `JSONError` if the key doesn't exist or the value is the wrong type, or if 0480 /// the receiver is not an object. 0481 /// - SeeAlso: `getObject(_:_:)` 0482 func getObject(key: Swift.String) throws -> JSONObject { 0483 return try getObject(key, { $0 }) 0484 } 0485 0486 /// Subscripts the receiver with `key` and returns the result. 0487 /// - Note: Use `getObjectOrNil(_:_:)` when using throwing accessors on the resulting 0488 /// object value to produce better errors. 0489 /// - Parameter key: The key that's used to subscript the receiver. 0490 /// - Returns: An object value, or `nil` if the key doesn't exist or the value is `null`. 0491 /// - Throws: `JSONError` if the value has the wrong type, or if the receiver is not an object. 0492 /// - SeeAlso: `getObjectOrNil(_:_:)` 0493 func getObjectOrNil(key: Swift.String) throws -> JSONObject? { 0494 return try getObjectOrNil(key, { $0 }) 0495 } 0496 0497 /// Subscripts the receiver with `key` and passes the result to the given block. 0498 /// - Parameter key: The key that's used to subscript the receiver. 0499 /// - Parameter transform: A block that's called with the result of subscripting the receiver with `key`. 0500 /// - Returns: The result of calling the given block. 0501 /// - Throws: `JSONError` if the key doesn't exist or the value is the wrong type, or if 0502 /// the receiver is not an object, or any error thrown by `transform`. 0503 func getObject
JSONError.swift:483
        return try getObject(key, { $0 })
<T>(key: Swift.String, @noescape _ transform: JSONObject throws -> T) throws -> T { 0504 return try getObject().getObject(key, transform) 0505 } 0506 0507 /// Subscripts the receiver with `key` and passes the result to the given block. 0508 /// - Parameter key: The key that's used to subscript the receiver. 0509 /// - Parameter transform: A block that's called with the result of subscripting the receiver with `key`. 0510 /// - Returns: The result of calling the given block, or `nil` if the key doesn't exist or the value is `null`. 0511 /// - Throws: `JSONError` if the value has the wrong type, or if the receiver is not an object, 0512 /// or any error thrown by `transform`. 0513 func getObjectOrNil
JSONError.swift:494
        return try getObjectOrNil(key, { $0 })
<T>(key: Swift.String, @noescape _ transform: JSONObject throws -> T?) throws -> T? { 0514 return try getObject().getObjectOrNil(key, transform) 0515 } 0516 0517 /// Subscripts the receiver with `key` and returns the result. 0518 /// - Note: Use `getArray(_:_:)` when using throwing accessors on the resulting 0519 /// array value to produce better errors. 0520 /// - Parameter key: The key that's used to subscript the receiver. 0521 /// - Throws: `JSONError` if the key doesn't exist or the value is the wrong type, or if 0522 /// the receiver is not an object. 0523 /// - SeeAlso: `getArray(_:_:)` 0524 func getArray(key: Swift.String) throws -> JSONArray { 0525 return try getArray(key, { $0 }) 0526 } 0527 0528 /// Subscripts the receiver with `key` and returns the result. 0529 /// - Note: Use `getArrayOrNil(_:_:)` when using throwing accessors on the resulting 0530 /// array value to produce better errors. 0531 /// - Parameter key: The key that's used to subscript the receiver. 0532 /// - Returns: An array value, or `nil` if the key doesn't exist or the value is `null`. 0533 /// - Throws: `JSONError` if the value has the wrong type. 0534 /// - SeeAlso: `getArrayOrNil(_:_:)` 0535 func getArrayOrNil(key: Swift.String) throws -> JSONArray? { 0536 return try getArrayOrNil(key, { $0 }) 0537 } 0538 0539 /// Subscripts the receiver with `key` and passes the result to the given block. 0540 /// - Parameter key: The key that's used to subscript the receiver. 0541 /// - Parameter transform: A block that's called with the result of subscripting the receiver with `key`. 0542 /// - Returns: The result of calling the given block. 0543 /// - Throws: `JSONError` if the key doesn't exist or the value is the wrong type, or if 0544 /// the receiver is not an object, or any error thrown by `transform`. 0545 func getArray
JSONError.swift:525
        return try getArray(key, { $0 })
<T>(key: Swift.String, @noescape _ transform: JSONArray throws -> T) throws -> T { 0546 let dict = try getObject() 0547 let value = try getRequired(dict, key: key, type: .Array) 0548 return try scoped(key) { try transform(value.getArray()) } 0549 } 0550 0551 /// Subscripts the receiver with `key` and passes the result to the given block. 0552 /// - Parameter key: The key that's used to subscript the receiver. 0553 /// - Parameter transform: A block that's called with the result of subscripting the receiver with `key`. 0554 /// - Returns: The result of calling the given block, or `nil` if the key doesn't exist or the value is `null`. 0555 /// - Throws: `JSONError` if the value has the wrong type, or if the receiver is not an object, 0556 /// or any error thrown by `transform`. 0557 func getArrayOrNil
JSONError.swift:536
        return try getArrayOrNil(key, { $0 })
<T>(key: Swift.String, @noescape _ transform: JSONArray throws -> T?) throws -> T? { 0558 let dict = try getObject() 0559 guard let value = dict[key] else { return nil } 0560 return try scoped(key) { try value.getArrayOrNil().flatMap(transform) } 0561 } 0562 } 0563 0564 public extension JSON { 0565 /// Subscripts the receiver with `key` and returns the result coerced to a `String`. 0566 /// - Parameter key: The key that's used to subscript the receiver. 0567 /// - Returns: A `String` value. 0568 /// - Throws: `JSONError` if the key doesn't exist, the value is an object or an array, 0569 /// or if the receiver is not an object. 0570 /// - SeeAlso: `toString()`. 0571 func toString(key: Swift.String) throws -> Swift.String { 0572 let dict = try getObject() 0573 let value = try getRequired(dict, key: key, type: .String) 0574 return try scoped(key) { try value.toString() } 0575 } 0576 0577 /// Subscripts the receiver with `key` and returns the result coerced to a `String`. 0578 /// - Parameter key: The key that's used to subscript the receiver. 0579 /// - Returns: A `String` value, or `nil` if the key doesn't exist or the value is `null`. 0580 /// - Throws: `JSONError` if the value is an object or an array, or if the receiver is not an object. 0581 /// - SeeAlso: `toStringOrNil()`. 0582 func toStringOrNil(key: Swift.String) throws -> Swift.String? { 0583 let dict = try getObject() 0584 guard let value = dict[key] else { return nil } 0585 return try scoped(key) { try value.toStringOrNil() } 0586 } 0587 0588 /// Subscripts the receiver with `key` and returns the result coerced to an `Int64`. 0589 /// - Parameter key: The key that's used to subscript the receiver. 0590 /// - Returns: An `Int64` value. 0591 /// - Throws: `JSONError` if the key doesn't exist or the value is `null`, a boolean, an object, 0592 /// an array, a string that cannot be coerced to a 64-bit integral value, or a floating-point 0593 /// value that does not fit in 64 bits, or if the receiver is not an object. 0594 func toInt64(key: Swift.String) throws -> Swift.Int64 { 0595 let dict = try getObject() 0596 let value = try getRequired(dict, key: key, type: .Number) 0597 return try scoped(key) { try value.toInt64() } 0598 } 0599 0600 /// Subscripts the receiver with `key` and returns the result coerced to an `Int64`. 0601 /// - Parameter key: The key that's used to subscript the receiver. 0602 /// - Returns: An `Int64` value, or `nil` if the key doesn't exist or the value is `null`. 0603 /// - Throws: `JSONError` if the the value is a boolean, an object, an array, a string 0604 /// that cannot be coerced to a 64-bit integral value, or a floating-point value 0605 /// that does not fit in 64 bits, or if the receiver is not an object. 0606 func toInt64OrNil(key: Swift.String) throws -> Swift.Int64? { 0607 let dict = try getObject() 0608 guard let value = dict[key] else { return nil } 0609 return try scoped(key) { try value.toInt64OrNil() } 0610 } 0611 0612 /// Subscripts the receiver with `key` and returns the result coerced to an `Int`. 0613 /// - Parameter key: The key that's used to subscript the receiver. 0614 /// - Returns: An `Int` value. 0615 /// - Throws: `JSONError` if the key doesn't exist or the value is `null`, a boolean, an object, 0616 /// an array, a string that cannot be coerced to an integral value, or a floating-point 0617 /// value that does not fit in an `Int`, or if the receiver is not an object. 0618 func toInt(key: Swift.String) throws -> Int { 0619 let dict = try getObject() 0620 let value = try getRequired(dict, key: key, type: .Number) 0621 return try scoped(key) { try value.toInt() } 0622 } 0623 0624 /// Subscripts the receiver with `key` and returns the result coerced to an `Int`. 0625 /// - Parameter key: The key that's used to subscript the receiver. 0626 /// - Returns: An `Int` value, or `nil` if the key doesn't exist or the value is `null`. 0627 /// - Throws: `JSONError` if the the value is a boolean, an object, an array, a string 0628 /// that cannot be coerced to an integral value, or a floating-point value 0629 /// that does not fit in an `Int`, or if the receiver is not an object. 0630 func toIntOrNil(key: Swift.String) throws -> Int? { 0631 let dict = try getObject() 0632 guard let value = dict[key] else { return nil } 0633 return try scoped(key) { try value.toIntOrNil() } 0634 } 0635 0636 /// Subscripts the receiver with `key` and returns the result coerced to a `Double`. 0637 /// - Parameter key: The key that's used to subscript the receiver. 0638 /// - Returns: A `Double` value. 0639 /// - Throws: `JSONError` if the key doesn't exist or the value is `null`, a boolean, 0640 /// an object, an array, or a string that cannot be coerced to a floating-point value, 0641 /// or if the receiver is not an object. 0642 func toDouble(key: Swift.String) throws -> Swift.Double { 0643 let dict = try getObject() 0644 let value = try getRequired(dict, key: key, type: .Number) 0645 return try scoped(key) { try value.toDouble() } 0646 } 0647 0648 /// Subscripts the receiver with `key` and returns the result coerced to a `Double`. 0649 /// - Parameter key: The key that's used to subscript the receiver. 0650 /// - Returns: A `Double` value, or `nil` if the key doesn't exist or the value is `null`. 0651 /// - Throws: `JSONError` if the value is a boolean, an object, an array, or a string that 0652 /// cannot be coerced to a floating-point value, or if the receiver is not an object. 0653 func toDoubleOrNil(key: Swift.String) throws -> Swift.Double? { 0654 let dict = try getObject() 0655 guard let value = dict[key] else { return nil } 0656 return try scoped(key) { try value.toDoubleOrNil() } 0657 } 0658 } 0659 0660 // MARK: - Indexed accessors 0661 public extension JSON { 0662 /// Subscripts the receiver with `index` and returns the result. 0663 /// - Parameter index: The index that's used to subscript the receiver. 0664 /// - Returns: A `Bool` value. 0665 /// - Throws: `JSONError` if the index is out of bounds or the value is the wrong type, 0666 /// or if the receiver is not an array. 0667 func getBool(index: Int) throws -> Swift.Bool { 0668 let ary = try getArray() 0669 let value = try getRequired(ary, index: index, type: .Bool) 0670 return try scoped(index) { try value.getBool() } 0671 } 0672 0673 /// Subscripts the receiver with `index` and returns the result. 0674 /// - Parameter index: The index that's used to subscript the receiver. 0675 /// - Returns: A `Bool` value, or `nil` if the index is out of bounds or the value is `null`. 0676 /// - Throws: `JSONError` if the value has the wrong type, or if the receiver is not an array. 0677 func getBoolOrNil(index: Int) throws -> Swift.Bool? { 0678 let ary = try getArray() 0679 guard let value = ary[safe: index] else { return nil } 0680 return try scoped(index) { try value.getBoolOrNil() } 0681 } 0682 0683 /// Subscripts the receiver with `index` and returns the result. 0684 /// - Parameter index: The index that's used to subscript the receiver. 0685 /// - Returns: A `String` value. 0686 /// - Throws: `JSONError` if the index is out of bounds or the value is the wrong type, 0687 /// or if the receiver is not an array. 0688 func getString(index: Int) throws -> Swift.String { 0689 let ary = try getArray() 0690 let value = try getRequired(ary, index: index, type: .String) 0691 return try scoped(index) { try value.getString() } 0692 } 0693 0694 /// Subscripts the receiver with `index` and returns the result. 0695 /// - Parameter index: The index that's used to subscript the receiver. 0696 /// - Returns: A `String` value, or `nil` if the index is out of bounds or the value is `null`. 0697 /// - Throws: `JSONError` if the value has the wrong type, or if the receiver is not an array. 0698 func getStringOrNil(index: Int) throws -> Swift.String? { 0699 let ary = try getArray() 0700 guard let value = ary[safe: index] else { return nil } 0701 return try scoped(index) { try value.getStringOrNil() } 0702 } 0703 0704 /// Subscripts the receiver with `index` and returns the result. 0705 /// - Parameter index: The index that's used to subscript the receiver. 0706 /// - Returns: An `Int64` value. 0707 /// - Throws: `JSONError` if the index is out of bounds or the value is the wrong type, 0708 /// or if the receiver is not an array. 0709 func getInt64(index: Int) throws -> Swift.Int64 { 0710 let ary = try getArray() 0711 let value = try getRequired(ary, index: index, type: .Number) 0712 return try scoped(index) { try value.getInt64() } 0713 } 0714 0715 /// Subscripts the receiver with `index` and returns the result. 0716 /// - Parameter index: The index that's used to subscript the receiver. 0717 /// - Returns: An `Int64` value, or `nil` if the index is out of bounds or the value is `null`. 0718 /// - Throws: `JSONError` if the value has the wrong type, or if the receiver is not an array. 0719 func getInt64OrNil(index: Int) throws -> Swift.Int64? { 0720 let ary = try getArray() 0721 guard let value = ary[safe: index] else { return nil } 0722 return try scoped(index) { try value.getInt64OrNil() } 0723 } 0724 0725 /// Subscripts the receiver with `index` and returns the result. 0726 /// - Parameter index: The index that's used to subscript the receiver. 0727 /// - Returns: An `Int` value. 0728 /// - Throws: `JSONError` if the index is out of bounds or the value is the wrong type, 0729 /// or if the 64-bit integral value is too large to fit in an `Int`, or if 0730 /// the receiver is not an array. 0731 func getInt(index: Int) throws -> Int { 0732 let ary = try getArray() 0733 let value = try getRequired(ary, index: index, type: .Number) 0734 return try scoped(index) { try value.getInt() } 0735 } 0736 0737 /// Subscripts the receiver with `index` and returns the result. 0738 /// - Parameter index: The index that's used to subscript the receiver. 0739 /// - Returns: An `Int` value, or `nil` if the index is out of bounds or the value is `null`. 0740 /// - Throws: `JSONError` if the value has the wrong type, or if the 64-bit integral value 0741 /// is too large to fit in an `Int`, or if the receiver is not an array. 0742 func getIntOrNil(index: Int) throws -> Int? { 0743 let ary = try getArray() 0744 guard let value = ary[safe: index] else { return nil } 0745 return try scoped(index) { try value.getIntOrNil() } 0746 } 0747 0748 /// Subscripts the receiver with `index` and returns the result. 0749 /// - Parameter index: The index that's used to subscript the receiver. 0750 /// - Returns: A `Double` value. 0751 /// - Throws: `JSONError` if the index is out of bounds or the value is the wrong type, 0752 /// or if the receiver is not an array. 0753 func getDouble(index: Int) throws -> Swift.Double { 0754 let ary = try getArray() 0755 let value = try getRequired(ary, index: index, type: .Number) 0756 return try scoped(index) { try value.getDouble() } 0757 } 0758 0759 /// Subscripts the receiver with `index` and returns the result. 0760 /// - Parameter index: The index that's used to subscript the receiver. 0761 /// - Returns: A `Double` value, or `nil` if the index is out of bounds or the value is `null`. 0762 /// - Throws: `JSONError` if the value has the wrong type, or if the receiver is not an array. 0763 func getDoubleOrNil(index: Int) throws -> Swift.Double? { 0764 let ary = try getArray() 0765 guard let value = ary[safe: index] else { return nil } 0766 return try scoped(index) { try value.getDoubleOrNil() } 0767 } 0768 0769 /// Subscripts the receiver with `index` and returns the result. 0770 /// - Note: Use `getObject(_:_:)` when using throwing accessors on the resulting 0771 /// object value to produce better errors. 0772 /// - Parameter index: The index that's used to subscript the receiver. 0773 /// - Returns: An object value. 0774 /// - Throws: `JSONError` if the index is out of bounds or the value is the wrong type, 0775 /// or if the receiver is not an array. 0776 /// - SeeAlso: `getObject(_:_:)` 0777 func getObject(index: Int) throws -> JSONObject { 0778 return try getObject(index, { $0 }) 0779 } 0780 0781 /// Subscripts the receiver with `index` and returns the result. 0782 /// - Note: Use `getObjectOrNil(_:_:)` when using throwing accessors on the resulting 0783 /// object value to produce better errors. 0784 /// - Parameter index: The index that's used to subscript the receiver. 0785 /// - Returns: An object value, or `nil` if the index is out of bounds or the value is `null`. 0786 /// - Throws: `JSONError` if the value has the wrong type, or if the receiver is not an array. 0787 /// - SeeAlso: `getObjectOrNil(_:_:)` 0788 func getObjectOrNil(index: Int) throws -> JSONObject? { 0789 return try getObjectOrNil(index, { $0 }) 0790 } 0791 0792 /// Subscripts the receiver with `index` and passes the result to the given block. 0793 /// - Parameter index: The index that's used to subscript the receiver. 0794 /// - Parameter transform: A block that's called with the result of subscripting the receiver with `index`. 0795 /// - Returns: The result of calling the given block. 0796 /// - Throws: `JSONError` if the index is out of bounds or the value is the wrong type, 0797 /// or if the receiver is not an array, or any error thrown by `transform`. 0798 func getObject
JSONError.swift:778
        return try getObject(index, { $0 })
<T>(index: Int, @noescape _ f: JSONObject throws -> T) throws -> T { 0799 let ary = try getArray() 0800 let value = try getRequired(ary, index: index, type: .Object) 0801 return try scoped(index) { try f(value.getObject()) } 0802 } 0803 0804 /// Subscripts the receiver with `index` and passes the result to the given block. 0805 /// - Parameter index: The index that's used to subscript the receiver. 0806 /// - Parameter transform: A block that's called with the result of subscripting the receiver with `index`. 0807 /// - Returns: The result of calling the given block, or `nil` if the index is out of bounds or the value is `null`. 0808 /// - Throws: `JSONError` if the value has the wrong type, or if the receiver is not an array, 0809 //// or any error thrown by `transform`. 0810 func getObjectOrNil
JSONError.swift:789
        return try getObjectOrNil(index, { $0 })
<T>(index: Int, @noescape _ f: JSONObject throws -> T?) throws -> T? { 0811 let ary = try getArray() 0812 guard let value = ary[safe: index] else { return nil } 0813 return try scoped(index) { try value.getObjectOrNil().flatMap(f) } 0814 } 0815 0816 /// Subscripts the receiver with `index` and returns the result. 0817 /// - Note: Use `getArray(_:_:)` when using throwing accessors on the resulting 0818 /// array value to produce better errors. 0819 /// - Parameter index: The index that's used to subscript the receiver. 0820 /// - Returns: An array value. 0821 /// - Throws: `JSONError` if the index is out of bounds or the value is the wrong type, 0822 /// or if the receiver is not an array. 0823 /// - SeeAlso: `getArray(_:_:)` 0824 func getArray(index: Int) throws -> JSONArray { 0825 return try getArray(index, { $0 }) 0826 } 0827 0828 /// Subscripts the receiver with `index` and returns the result. 0829 /// - Note: Use `getArrayOrNil(_:_:)` when using throwing accessors on the resulting 0830 /// array value to produce better errors. 0831 /// - Parameter index: The index that's used to subscript the receiver. 0832 /// - Returns: An array value, or `nil` if the index is out of bounds or the value is `null`. 0833 /// - Throws: `JSONError` if the value has the wrong type, or if the receiver is not an array. 0834 /// - SeeAlso: `getArrayOrNil(_:_:)` 0835 func getArrayOrNil(index: Int) throws -> JSONArray? { 0836 return try getArrayOrNil(index, { $0 }) 0837 } 0838 0839 /// Subscripts the receiver with `index` and passes the result to the given block. 0840 /// - Parameter index: The index that's used to subscript the receiver. 0841 /// - Parameter transform: A block that's called with the result of subscripting the receiver with `index`. 0842 /// - Returns: The result of calling the given block. 0843 /// - Throws: `JSONError` if the index is out of bounds or the value is the wrong type, 0844 /// or if the receiver is not an array, or any error thrown by `transform`. 0845 func getArray
JSONError.swift:825
        return try getArray(index, { $0 })
<T>(index: Int, @noescape _ f: JSONArray throws -> T) throws -> T { 0846 let ary = try getArray() 0847 let value = try getRequired(ary, index: index, type: .Array) 0848 return try scoped(index) { try f(value.getArray()) } 0849 } 0850 0851 /// Subscripts the receiver with `index` and passes the result to the given block. 0852 /// - Parameter index: The index that's used to subscript the receiver. 0853 /// - Parameter transform: A block that's called with the result of subscripting the receiver with `index`. 0854 /// - Returns: The result of calling the given block, or `nil` if the index is out of bounds or the value is `null`. 0855 /// - Throws: `JSONError` if the value has the wrong type, or if the receiver is not an array, 0856 /// or any error thrown by `transform`. 0857 func getArrayOrNil
JSONError.swift:836
        return try getArrayOrNil(index, { $0 })
<T>(index: Int, @noescape _ f: JSONArray throws -> T?) throws -> T? { 0858 let ary = try getArray() 0859 guard let value = ary[safe: index] else { return nil } 0860 return try scoped(index) { try value.getArrayOrNil().flatMap(f) } 0861 } 0862 } 0863 0864 public extension JSON { 0865 /// Subscripts the receiver with `index` and returns the result coerced to a `String`. 0866 /// - Parameter index: The index that's used to subscript the receiver. 0867 /// - Returns: A `String` value. 0868 /// - Throws: `JSONError` if the index is out of bounds or the value is an object or an array, 0869 /// or if the receiver is not an array. 0870 /// - SeeAlso: `toString()`. 0871 func toString(index: Int) throws -> Swift.String { 0872 let ary = try getArray() 0873 let value = try getRequired(ary, index: index, type: .String) 0874 return try scoped(index) { try value.toString() } 0875 } 0876 0877 /// Subscripts the receiver with `index` and returns the result coerced to a `String`. 0878 /// - Parameter index: The index that's used to subscript the receiver. 0879 /// - Returns: A `String` value, or `nil` if the index is out of bounds or the value is `null`. 0880 /// - Throws: `JSONError` if the value is an object or an array, or if the receiver is not an array. 0881 /// - SeeAlso: `toStringOrNil()`. 0882 func toStringOrNil(index: Int) throws -> Swift.String? { 0883 let ary = try getArray() 0884 guard let value = ary[safe: index] else { return nil } 0885 return try scoped(index) { try value.toStringOrNil() } 0886 } 0887 0888 /// Subscripts the receiver with `index` and returns the result coerced to an `Int64`. 0889 /// - Parameter index: The index that's used to subscript the receiver. 0890 /// - Returns: An `Int64` value. 0891 /// - Throws: `JSONError` if the index is out of bounds or the value is `null`, a boolean, 0892 /// an object, an array, a string that cannot be coerced to a 64-bit integral value, or a 0893 /// floating-point value that does not fit in 64 bits, or if the receiver is not an array. 0894 /// - SeeAlso: `toInt64()`. 0895 func toInt64(index: Int) throws -> Swift.Int64 { 0896 let ary = try getArray() 0897 let value = try getRequired(ary, index: index, type: .Number) 0898 return try scoped(index) { try value.toInt64() } 0899 } 0900 0901 /// Subscripts the receiver with `index` and returns the result coerced to an `Int64`. 0902 /// - Parameter index: The index that's used to subscript the receiver. 0903 /// - Returns: An `Int64` value, or `nil` if the index is out of bounds or the value is `null`. 0904 /// - Throws: `JSONError` if the the value is a boolean, an object, an array, a string 0905 /// that cannot be coerced to a 64-bit integral value, or a floating-point value 0906 /// that does not fit in 64 bits, or if the receiver is not an array. 0907 /// - SeeAlso: `toInt64OrNil()`. 0908 func toInt64OrNil(index: Int) throws -> Swift.Int64? { 0909 let ary = try getArray() 0910 guard let value = ary[safe: index] else { return nil } 0911 return try scoped(index) { try value.toInt64OrNil() } 0912 } 0913 0914 /// Subscripts the receiver with `index` and returns the result coerced to an `Int`. 0915 /// - Parameter index: The index that's used to subscript the receiver. 0916 /// - Returns: An `Int` value. 0917 /// - Throws: `JSONError` if the index is out of bounds or the value is `null`, a boolean, 0918 /// an object, an array, a string that cannot be coerced to an integral value, or a 0919 /// floating-point value that does not fit in an `Int`, or if the receiver is not an array. 0920 /// - SeeAlso: `toInt()`. 0921 func toInt(index: Int) throws -> Int { 0922 let ary = try getArray() 0923 let value = try getRequired(ary, index: index, type: .Number) 0924 return try scoped(index) { try value.toInt() } 0925 } 0926 0927 /// Subscripts the receiver with `index` and returns the result coerced to an `Int`. 0928 /// - Parameter index: The index that's used to subscript the receiver. 0929 /// - Returns: An `Int` value, or `nil` if the index is out of bounds or the value is `null`. 0930 /// - Throws: `JSONError` if the the value is a boolean, an object, an array, a string 0931 /// that cannot be coerced to an integral value, or a floating-point value 0932 /// that does not fit in an `Int`, or if the receiver is not an array. 0933 /// - SeeAlso: `toIntOrNil()`. 0934 func toIntOrNil(index: Int) throws -> Int? { 0935 let ary = try getArray() 0936 guard let value = ary[safe: index] else { return nil } 0937 return try scoped(index) { try value.toIntOrNil() } 0938 } 0939 0940 /// Subscripts the receiver with `index` and returns the result coerced to a `Double`. 0941 /// - Parameter index: The index that's used to subscript the receiver. 0942 /// - Returns: A `Double` value. 0943 /// - Throws: `JSONError` if the index is out of bounds or the value is `null`, a boolean, 0944 /// an object, an array, or a string that cannot be coerced to a floating-point value, 0945 /// or if the receiver is not an array. 0946 /// - SeeAlso: `toDouble()`. 0947 func toDouble(index: Int) throws -> Swift.Double { 0948 let ary = try getArray() 0949 let value = try getRequired(ary, index: index, type: .Number) 0950 return try scoped(index) { try value.toDouble() } 0951 } 0952 0953 /// Subscripts the receiver with `index` and returns the result coerced to a `Double`. 0954 /// - Parameter index: The index that's used to subscript the receiver. 0955 /// - Returns: A `Double` value, or `nil` if the index is out of bounds or the value is `null`. 0956 /// - Throws: `JSONError` if the value is a boolean, an object, an array, or a string that 0957 /// cannot be coerced to a floating-point value, or if the receiver is not an array. 0958 /// - SeeAlso: `toDouble()`. 0959 func toDoubleOrNil(index: Int) throws -> Swift.Double? { 0960 let ary = try getArray() 0961 guard let value = ary[safe: index] else { return nil } 0962 return try scoped(index) { try value.toDoubleOrNil() } 0963 } 0964 } 0965 0966 // MARK: - 0967 0968 public extension JSONObject { 0969 /// Subscripts the receiver with `key` and returns the result. 0970 /// - Parameter key: The key that's used to subscript the receiver. 0971 /// - Returns: A `Bool` value. 0972 /// - Throws: `JSONError` if the key doesn't exist or the value is the wrong type. 0973 func getBool(key: Swift.String) throws -> Swift.Bool { 0974 let value = try getRequired(self, key: key, type: .String) 0975 return try scoped(key) { try value.getBool() } 0976 } 0977 0978 /// Subscripts the receiver with `key` and returns the result. 0979 /// - Parameter key: The key that's used to subscript the receiver. 0980 /// - Returns: A `Bool` value, or `nil` if the key doesn't exist or the value is `null`. 0981 /// - Throws: `JSONError` if the value has the wrong type. 0982 func getBoolOrNil(key: Swift.String) throws -> Swift.Bool? { 0983 guard let value = self[key] else { return nil } 0984 return try scoped(key) { try value.getBoolOrNil() } 0985 } 0986 0987 /// Subscripts the receiver with `key` and returns the result. 0988 /// - Parameter key: The key that's used to subscript the receiver. 0989 /// - Returns: A `String` value. 0990 /// - Throws: `JSONError` if the key doesn't exist or the value is the wrong type. 0991 func getString(key: Swift.String) throws -> Swift.String { 0992 let value = try getRequired(self, key: key, type: .String) 0993 return try scoped(key) { try value.getString() } 0994 } 0995 0996 /// Subscripts the receiver with `key` and returns the result. 0997 /// - Parameter key: The key that's used to subscript the receiver. 0998 /// - Returns: A `String` value, or `nil` if the key doesn't exist or the value is `null`. 0999 /// - Throws: `JSONError` if the value has the wrong type. 1000 func getStringOrNil(key: Swift.String) throws -> Swift.String? { 1001 guard let value = self[key] else { return nil } 1002 return try scoped(key) { try value.getStringOrNil() } 1003 } 1004 1005 /// Subscripts the receiver with `key` and returns the result. 1006 /// - Parameter key: The key that's used to subscript the receiver. 1007 /// - Returns: An `Int64` value. 1008 /// - Throws: `JSONError` if the key doesn't exist or the value is the wrong type. 1009 func getInt64(key: Swift.String) throws -> Swift.Int64 { 1010 let value = try getRequired(self, key: key, type: .Number) 1011 return try scoped(key) { try value.getInt64() } 1012 } 1013 1014 /// Subscripts the receiver with `key` and returns the result. 1015 /// - Parameter key: The key that's used to subscript the receiver. 1016 /// - Returns: An `Int64` value, or `nil` if the key doesn't exist or the value is `null`. 1017 /// - Throws: `JSONError` if the value has the wrong type. 1018 func getInt64OrNil(key: Swift.String) throws -> Swift.Int64? { 1019 guard let value = self[key] else { return nil } 1020 return try scoped(key) { try value.getInt64OrNil() } 1021 } 1022 1023 /// Subscripts the receiver with `key` and returns the result. 1024 /// - Parameter key: The key that's used to subscript the receiver. 1025 /// - Returns: An `Int` value. 1026 /// - Throws: `JSONError` if the key doesn't exist or the value is the wrong type, 1027 /// or if the 64-bit integral value is too large to fit in an `Int`. 1028 func getInt(key: Swift.String) throws -> Int { 1029 let value = try getRequired(self, key: key, type: .Number) 1030 return try scoped(key) { try value.getInt() } 1031 } 1032 1033 /// Subscripts the receiver with `key` and returns the result. 1034 /// - Parameter key: The key that's used to subscript the receiver. 1035 /// - Returns: An `Int` value, or `nil` if the key doesn't exist or the value is `null`. 1036 /// - Throws: `JSONError` if the value has the wrong type, or if the 64-bit integral 1037 /// value is too large to fit in an `Int`. 1038 func getIntOrNil(key: Swift.String) throws -> Int? { 1039 guard let value = self[key] else { return nil } 1040 return try scoped(key) { try value.getIntOrNil() } 1041 } 1042 1043 /// Subscripts the receiver with `key` and returns the result. 1044 /// - Parameter key: The key that's used to subscript the receiver. 1045 /// - Returns: A `Double` value. 1046 /// - Throws: `JSONError` if the key doesn't exist or the value is the wrong type. 1047 func getDouble(key: Swift.String) throws -> Swift.Double { 1048 let value = try getRequired(self, key: key, type: .Number) 1049 return try scoped(key) { try value.getDouble() } 1050 } 1051 1052 /// Subscripts the receiver with `key` and returns the result. 1053 /// - Parameter key: The key that's used to subscript the receiver. 1054 /// - Returns: A `Double` value, or `nil` if the key doesn't exist or the value is `null`. 1055 /// - Throws: `JSONError` if the value has the wrong type. 1056 func getDoubleOrNil(key: Swift.String) throws -> Swift.Double? { 1057 guard let value = self[key] else { return nil } 1058 return try scoped(key) { try value.getDoubleOrNil() } 1059 } 1060 1061 /// Subscripts the receiver with `key` and returns the result. 1062 /// - Note: Use `getObject(_:_:)` when using throwing accessors on the resulting 1063 /// object value to produce better errors. 1064 /// - Parameter key: The key that's used to subscript the receiver. 1065 /// - Returns: An object value. 1066 /// - Throws: `JSONError` if the key doesn't exist or the value is the wrong type. 1067 /// - SeeAlso: `getObject(_:_:)` 1068 func getObject(key: Swift.String) throws -> JSONObject { 1069 return try getObject(key, { $0 }) 1070 } 1071 1072 /// Subscripts the receiver with `key` and returns the result. 1073 /// - Note: Use `getObjectOrNil(_:_:)` when using throwing accessors on the resulting 1074 /// object value to produce better errors. 1075 /// - Parameter key: The key that's used to subscript the receiver. 1076 /// - Returns: An object value, or `nil` if the key doesn't exist or the value is `null`. 1077 /// - Throws: `JSONError` if the value has the wrong type. 1078 /// - SeeAlso: `getObjectOrNil(_:_:)` 1079 func getObjectOrNil(key: Swift.String) throws -> JSONObject? { 1080 return try getObjectOrNil(key, { $0 }) 1081 } 1082 1083 /// Subscripts the receiver with `key` and passes the result to the given block. 1084 /// - Parameter key: The key that's used to subscript the receiver. 1085 /// - Parameter transform: A block that's called with the result of subscripting the receiver with `key`. 1086 /// - Returns: The result of calling the given block. 1087 /// - Throws: `JSONError` if the key doesn't exist or the value is the wrong type, or any 1088 /// error thrown by `transform`. 1089 func getObject
JSONError.swift:504
        return try getObject().getObject(key, transform)
JSONError.swift:1069
        return try getObject(key, { $0 })
<T>(key: Swift.String, @noescape _ f: JSONObject throws -> T) throws -> T { 1090 let value = try getRequired(self, key: key, type: .Object) 1091 return try scoped(key) { try f(value.getObject()) } 1092 } 1093 1094 /// Subscripts the receiver with `key` and passes the result to the given block. 1095 /// - Parameter key: The key that's used to subscript the receiver. 1096 /// - Parameter transform: A block that's called with the result of subscripting the receiver with `key`. 1097 /// - Returns: The result of calling the given block, or `nil` if the key doesn't exist or the value is `null`. 1098 /// - Throws: `JSONError` if the value has the wrong type, or any error thrown by `transform`. 1099 func getObjectOrNil
JSONError.swift:514
        return try getObject().getObjectOrNil(key, transform)
JSONError.swift:1080
        return try getObjectOrNil(key, { $0 })
<T>(key: Swift.String, @noescape _ f: JSONObject throws -> T?) throws -> T? { 1100 guard let value = self[key] else { return nil } 1101 return try scoped(key) { try value.getObjectOrNil().flatMap(f) } 1102 } 1103 1104 /// Subscripts the receiver with `key` and returns the result. 1105 /// - Note: Use `getArray(_:_:)` when using throwing accessors on the resulting 1106 /// array value to produce better errors. 1107 /// - Parameter key: The key that's used to subscript the receiver. 1108 /// - Throws: `JSONError` if the key doesn't exist or the value is the wrong type. 1109 /// - SeeAlso: `getArray(_:_:)` 1110 func getArray(key: Swift.String) throws -> JSONArray { 1111 return try getArray(key, { $0 }) 1112 } 1113 1114 /// Subscripts the receiver with `key` and returns the result. 1115 /// - Note: Use `getArrayOrNil(_:_:)` when using throwing accessors on the resulting 1116 /// array value to produce better errors. 1117 /// - Parameter key: The key that's used to subscript the receiver. 1118 /// - Returns: An array value, or `nil` if the key doesn't exist or the value is `null`. 1119 /// - Throws: `JSONError` if the value has the wrong type. 1120 /// - SeeAlso: `getArrayOrNil(_:_:)` 1121 func getArrayOrNil(key: Swift.String) throws -> JSONArray? { 1122 return try getArrayOrNil(key, { $0 }) 1123 } 1124 1125 /// Subscripts the receiver with `key` and passes the result to the given block. 1126 /// - Parameter key: The key that's used to subscript the receiver. 1127 /// - Parameter transform: A block that's called with the result of subscripting the receiver with `key`. 1128 /// - Returns: The result of calling the given block. 1129 /// - Throws: `JSONError` if the key doesn't exist or the value is the wrong type, or any 1130 /// error thrown by `transform`. 1131 func getArray
JSONError.swift:1111
        return try getArray(key, { $0 })
<T>(key: Swift.String, @noescape _ f: JSONArray throws -> T) throws -> T { 1132 let value = try getRequired(self, key: key, type: .Array) 1133 return try scoped(key) { try f(value.getArray()) } 1134 } 1135 1136 /// Subscripts the receiver with `key` and passes the result to the given block. 1137 /// - Parameter key: The key that's used to subscript the receiver. 1138 /// - Parameter transform: A block that's called with the result of subscripting the receiver with `key`. 1139 /// - Returns: The result of calling the given block, or `nil` if the key doesn't exist or the value is `null`. 1140 /// - Throws: `JSONError` if the value has the wrong type, or any error thrown by `transform`. 1141 func getArrayOrNil
JSONError.swift:1122
        return try getArrayOrNil(key, { $0 })
<T>(key: Swift.String, @noescape _ f: JSONArray throws -> T?) throws -> T? { 1142 guard let value = self[key] else { return nil } 1143 return try scoped(key) { try value.getArrayOrNil().flatMap(f) } 1144 } 1145 } 1146 1147 public extension JSONObject { 1148 /// Subscripts the receiver with `key` and returns the result coerced to a `String`. 1149 /// - Parameter key: The key that's used to subscript the receiver. 1150 /// - Returns: A `String` value. 1151 /// - Throws: `JSONError` if the key doesn't exist, the value is an object or an array, 1152 /// or if the receiver is not an object. 1153 /// - SeeAlso: `toString()`. 1154 func toString(key: Swift.String) throws -> Swift.String { 1155 let value = try getRequired(self, key: key, type: .String) 1156 return try scoped(key) { try value.toString() } 1157 } 1158 1159 /// Subscripts the receiver with `key` and returns the result coerced to a `String`. 1160 /// - Parameter key: The key that's used to subscript the receiver. 1161 /// - Returns: A `String` value, or `nil` if the key doesn't exist or the value is `null`. 1162 /// - Throws: `JSONError` if the value is an object or an array, or if the receiver is not an object. 1163 /// - SeeAlso: `toStringOrNil()`. 1164 func toStringOrNil(key: Swift.String) throws -> Swift.String? { 1165 guard let value = self[key] else { return nil } 1166 return try scoped(key) { try value.toStringOrNil() } 1167 } 1168 1169 /// Subscripts the receiver with `key` and returns the result coerced to an `Int64`. 1170 /// - Parameter key: The key that's used to subscript the receiver. 1171 /// - Returns: An `Int64` value. 1172 /// - Throws: `JSONError` if the key doesn't exist or the value is `null`, a boolean, an object, 1173 /// an array, a string that cannot be coerced to a 64-bit integral value, or a floating-point 1174 /// value that does not fit in 64 bits, or if the receiver is not an object. 1175 func toInt64(key: Swift.String) throws -> Swift.Int64 { 1176 let value = try getRequired(self, key: key, type: .Number) 1177 return try scoped(key) { try value.toInt64() } 1178 } 1179 1180 /// Subscripts the receiver with `key` and returns the result coerced to an `Int64`. 1181 /// - Parameter key: The key that's used to subscript the receiver. 1182 /// - Returns: An `Int64` value, or `nil` if the key doesn't exist or the value is `null`. 1183 /// - Throws: `JSONError` if the the value is a boolean, an object, an array, a string 1184 /// that cannot be coerced to a 64-bit integral value, or a floating-point value 1185 /// that does not fit in 64 bits, or if the receiver is not an object. 1186 func toInt64OrNil(key: Swift.String) throws -> Swift.Int64? { 1187 guard let value = self[key] else { return nil } 1188 return try scoped(key) { try value.toInt64OrNil() } 1189 } 1190 1191 /// Subscripts the receiver with `key` and returns the result coerced to an `Int`. 1192 /// - Parameter key: The key that's used to subscript the receiver. 1193 /// - Returns: An `Int` value. 1194 /// - Throws: `JSONError` if the key doesn't exist or the value is `null`, a boolean, an object, 1195 /// an array, a string that cannot be coerced to an integral value, or a floating-point 1196 /// value that does not fit in an `Int`, or if the receiver is not an object. 1197 func toInt(key: Swift.String) throws -> Int { 1198 let value = try getRequired(self, key: key, type: .Number) 1199 return try scoped(key) { try value.toInt() } 1200 } 1201 1202 /// Subscripts the receiver with `key` and returns the result coerced to an `Int`. 1203 /// - Parameter key: The key that's used to subscript the receiver. 1204 /// - Returns: An `Int` value, or `nil` if the key doesn't exist or the value is `null`. 1205 /// - Throws: `JSONError` if the the value is a boolean, an object, an array, a string 1206 /// that cannot be coerced to an integral value, or a floating-point value 1207 /// that does not fit in an `Int`, or if the receiver is not an object. 1208 func toIntOrNil(key: Swift.String) throws -> Int? { 1209 guard let value = self[key] else { return nil } 1210 return try scoped(key) { try value.toIntOrNil() } 1211 } 1212 1213 /// Subscripts the receiver with `key` and returns the result coerced to a `Double`. 1214 /// - Parameter key: The key that's used to subscript the receiver. 1215 /// - Returns: A `Double` value. 1216 /// - Throws: `JSONError` if the key doesn't exist or the value is `null`, a boolean, 1217 /// an object, an array, or a string that cannot be coerced to a floating-point value, 1218 /// or if the receiver is not an object. 1219 func toDouble(key: Swift.String) throws -> Swift.Double { 1220 let value = try getRequired(self, key: key, type: .Number) 1221 return try scoped(key) { try value.toDouble() } 1222 } 1223 1224 /// Subscripts the receiver with `key` and returns the result coerced to a `Double`. 1225 /// - Parameter key: The key that's used to subscript the receiver. 1226 /// - Returns: A `Double` value, or `nil` if the key doesn't exist or the value is `null`. 1227 /// - Throws: `JSONError` if the value is a boolean, an object, an array, or a string that 1228 /// cannot be coerced to a floating-point value, or if the receiver is not an object. 1229 func toDoubleOrNil(key: Swift.String) throws -> Swift.Double? { 1230 guard let value = self[key] else { return nil } 1231 return try scoped(key) { try value.toDoubleOrNil() } 1232 } 1233 } 1234 1235 // MARK: - JSONArray helpers 1236 1237 public extension JSON { 1238 /// Returns an `Array` containing the results of mapping `transform` over `array`. 1239 /// If `transform` throws a `JSONError`, the error will be modified to include the index 1240 /// of the element that caused the error. 1241 /// - Parameter array: The `JSONArray` to map over. 1242 /// - Parameter transform: A block that is called once for each element of `array`. 1243 /// - Returns: An array with the results of mapping `transform` over `array`. 1244 /// - Throws: Rethrows any error thrown by `transform`. 1245 /// - Complexity: O(*N*). 1246 /// - Bug: This method must be marked as `throws` instead of `rethrows` because of Swift compiler 1247 /// limitations. If you want to map an array with a non-throwing transform function, use 1248 /// `SequenceType.map` instead. 1249 static func map<T>(array: JSONArray, @noescape _ transform: JSON throws -> T) throws -> [T] { 1250 return try array.enumerate().map({ i, elt in try scoped(i, f: { try transform(elt) }) }) 1251 } 1252 1253 /// Returns an `Array` containing the non-`nil` results of mapping `transform` over `array`. 1254 /// If `transform` throws a `JSONError`, the error will be modified to include the index 1255 /// of the element that caused the error. 1256 /// - Parameter array: The `JSONArray` to map over. 1257 /// - Parameter transform: A block that is called once for each element of `array`. 1258 /// - Returns: An array with the non-`nil` results of mapping `transform` over `array`. 1259 /// - Throws: Rethrows any error thrown by `transform`. 1260 /// - Complexity: O(*M* + *N*) where *M* is the length of `array` and *N* is the length of the result. 1261 /// - Bug: This method must be marked as `throws` instead of `rethrows` because of Swift compiler 1262 /// limitations. If you want to map an array with a non-throwing transform function, use 1263 /// `SequenceType.flatMap` instead. 1264 static func flatMap<T>(array: JSONArray, @noescape _ transform: JSON throws -> T?) throws -> [T] { 1265 return try array.enumerate().flatMap({ i, elt in try scoped(i, f: { try transform(elt) }) }) 1266 } 1267 1268 /// Returns an `Array` containing the concatenated results of mapping `transform` over `array`. 1269 /// If `transform` throws a `JSONError`, the error will be modified to include the index 1270 /// of the element that caused the error. 1271 /// - Parameter array: The `JSONArray` to map over. 1272 /// - Parameter transform: A block that is called once for each element of `array`. 1273 /// - Returns: An array with the concatenated results of mapping `transform` over `array`. 1274 /// - Throws: Rethrows any error thrown by `transform`. 1275 /// - Complexity: O(*M* + *N*) where *M* is the length of `array` and *N* is the length of the result. 1276 /// - Bug: This method must be marked as `throws` instead of `rethrows` because of Swift compiler 1277 /// limitations. If you want to map an array with a non-throwing transform function, use 1278 /// `SequenceType.flatMap` instead. 1279 static func flatMap<S: SequenceType>(array: JSONArray, _ transform: JSON throws -> S) throws -> [S.Generator.Element] { 1280 // FIXME: Use SequenceType.flatMap() once it becomes @noescape 1281 var results: [S.Generator.Element] = [] 1282 for (i, elt) in array.enumerate() { 1283 try scoped(i) { 1284 results.appendContentsOf(try transform(elt)) 1285 } 1286 } 1287 return results 1288 } 1289 } 1290 1291 // MARK: - 1292 1293 internal func getRequired
DecimalNumber.swift:104
            let value = try getRequired(dict, key: key, type: .Number)
DecimalNumber.swift:127
            let value = try getRequired(dict, key: key, type: .Number)
DecimalNumber.swift:200
            let value = try getRequired(self, key: key, type: .Number)
DecimalNumber.swift:221
            let value = try getRequired(self, key: key, type: .Number)
JSONError.swift:374
        let value = try getRequired(dict, key: key, type: .String)
JSONError.swift:395
        let value = try getRequired(dict, key: key, type: .String)
JSONError.swift:416
        let value = try getRequired(dict, key: key, type: .Number)
JSONError.swift:438
        let value = try getRequired(dict, key: key, type: .Number)
JSONError.swift:460
        let value = try getRequired(dict, key: key, type: .Number)
JSONError.swift:547
        let value = try getRequired(dict, key: key, type: .Array)
JSONError.swift:573
        let value = try getRequired(dict, key: key, type: .String)
JSONError.swift:596
        let value = try getRequired(dict, key: key, type: .Number)
JSONError.swift:620
        let value = try getRequired(dict, key: key, type: .Number)
JSONError.swift:644
        let value = try getRequired(dict, key: key, type: .Number)
JSONError.swift:974
        let value = try getRequired(self, key: key, type: .String)
JSONError.swift:992
        let value = try getRequired(self, key: key, type: .String)
JSONError.swift:1010
        let value = try getRequired(self, key: key, type: .Number)
JSONError.swift:1029
        let value = try getRequired(self, key: key, type: .Number)
JSONError.swift:1048
        let value = try getRequired(self, key: key, type: .Number)
JSONError.swift:1090
        let value = try getRequired(self, key: key, type: .Object)
JSONError.swift:1132
        let value = try getRequired(self, key: key, type: .Array)
JSONError.swift:1155
        let value = try getRequired(self, key: key, type: .String)
JSONError.swift:1176
        let value = try getRequired(self, key: key, type: .Number)
JSONError.swift:1198
        let value = try getRequired(self, key: key, type: .Number)
JSONError.swift:1220
        let value = try getRequired(self, key: key, type: .Number)
(dict: JSONObject, key: String, type: JSONError.JSONType) throws -> JSON { 1294 guard let value = dict[key] else { throw JSONError.MissingOrInvalidType(path: key, expected: .Required(type), actual: nil) } 1295 return value 1296 } 1297 1298 internal func getRequired
DecimalNumber.swift:153
            let value = try getRequired(array, index: index, type: .Number)
DecimalNumber.swift:175
            let value = try getRequired(array, index: index, type: .Number)
JSONError.swift:669
        let value = try getRequired(ary, index: index, type: .Bool)
JSONError.swift:690
        let value = try getRequired(ary, index: index, type: .String)
JSONError.swift:711
        let value = try getRequired(ary, index: index, type: .Number)
JSONError.swift:733
        let value = try getRequired(ary, index: index, type: .Number)
JSONError.swift:755
        let value = try getRequired(ary, index: index, type: .Number)
JSONError.swift:800
        let value = try getRequired(ary, index: index, type: .Object)
JSONError.swift:847
        let value = try getRequired(ary, index: index, type: .Array)
JSONError.swift:873
        let value = try getRequired(ary, index: index, type: .String)
JSONError.swift:897
        let value = try getRequired(ary, index: index, type: .Number)
JSONError.swift:923
        let value = try getRequired(ary, index: index, type: .Number)
JSONError.swift:949
        let value = try getRequired(ary, index: index, type: .Number)
(ary: JSONArray, index: Int, type: JSONError.JSONType) throws -> JSON { 1299 guard let value = ary[safe: index] else { throw JSONError.MissingOrInvalidType(path: "[\(index)]", expected: .Required(type), actual: nil) } 1300 return value 1301 } 1302 1303 @inline(__always) 1304 internal func scoped
DecimalNumber.swift:105
            return try scoped(key) { try value.getDecimalNumber() }
DecimalNumber.swift:116
            return try scoped(key) { try value.getDecimalNumberOrNil() }
DecimalNumber.swift:128
            return try scoped(key) { try value.toDecimalNumber() }
DecimalNumber.swift:139
            return try scoped(key) { try value.toDecimalNumberOrNil() }
DecimalNumber.swift:201
            return try scoped(key) { try value.getDecimalNumber() }
DecimalNumber.swift:211
            return try scoped(key) { try value.getDecimalNumberOrNil() }
DecimalNumber.swift:222
            return try scoped(key) { try value.toDecimalNumber() }
DecimalNumber.swift:232
            return try scoped(key) { try value.toDecimalNumberOrNil() }
JSONError.swift:375
        return try scoped(key) { try value.getBool() }
JSONError.swift:385
        return try scoped(key) { try value.getBoolOrNil() }
JSONError.swift:396
        return try scoped(key) { try value.getString() }
JSONError.swift:406
        return try scoped(key) { try value.getStringOrNil() }
JSONError.swift:417
        return try scoped(key) { try value.getInt64() }
JSONError.swift:427
        return try scoped(key) { try value.getInt64OrNil() }
JSONError.swift:439
        return try scoped(key) { try value.getInt() }
JSONError.swift:450
        return try scoped(key) { try value.getIntOrNil() }
JSONError.swift:461
        return try scoped(key) { try value.getDouble() }
JSONError.swift:471
        return try scoped(key) { try value.getDoubleOrNil() }
JSONError.swift:548
        return try scoped(key) { try transform(value.getArray()) }
JSONError.swift:560
        return try scoped(key) { try value.getArrayOrNil().flatMap(transform) }
JSONError.swift:574
        return try scoped(key) { try value.toString() }
JSONError.swift:585
        return try scoped(key) { try value.toStringOrNil() }
JSONError.swift:597
        return try scoped(key) { try value.toInt64() }
JSONError.swift:609
        return try scoped(key) { try value.toInt64OrNil() }
JSONError.swift:621
        return try scoped(key) { try value.toInt() }
JSONError.swift:633
        return try scoped(key) { try value.toIntOrNil() }
JSONError.swift:645
        return try scoped(key) { try value.toDouble() }
JSONError.swift:656
        return try scoped(key) { try value.toDoubleOrNil() }
JSONError.swift:975
        return try scoped(key) { try value.getBool() }
JSONError.swift:984
        return try scoped(key) { try value.getBoolOrNil() }
JSONError.swift:993
        return try scoped(key) { try value.getString() }
JSONError.swift:1002
        return try scoped(key) { try value.getStringOrNil() }
JSONError.swift:1011
        return try scoped(key) { try value.getInt64() }
JSONError.swift:1020
        return try scoped(key) { try value.getInt64OrNil() }
JSONError.swift:1030
        return try scoped(key) { try value.getInt() }
JSONError.swift:1040
        return try scoped(key) { try value.getIntOrNil() }
JSONError.swift:1049
        return try scoped(key) { try value.getDouble() }
JSONError.swift:1058
        return try scoped(key) { try value.getDoubleOrNil() }
JSONError.swift:1091
        return try scoped(key) { try f(value.getObject()) }
JSONError.swift:1101
        return try scoped(key) { try value.getObjectOrNil().flatMap(f) }
JSONError.swift:1133
        return try scoped(key) { try f(value.getArray()) }
JSONError.swift:1143
        return try scoped(key) { try value.getArrayOrNil().flatMap(f) }
JSONError.swift:1156
        return try scoped(key) { try value.toString() }
JSONError.swift:1166
        return try scoped(key) { try value.toStringOrNil() }
JSONError.swift:1177
        return try scoped(key) { try value.toInt64() }
JSONError.swift:1188
        return try scoped(key) { try value.toInt64OrNil() }
JSONError.swift:1199
        return try scoped(key) { try value.toInt() }
JSONError.swift:1210
        return try scoped(key) { try value.toIntOrNil() }
JSONError.swift:1221
        return try scoped(key) { try value.toDouble() }
JSONError.swift:1231
        return try scoped(key) { try value.toDoubleOrNil() }
<T>(key: String, @noescape f: () throws -> T) throws -> T { 1305 do { 1306 return try f() 1307 } catch let error as JSONError { 1308 throw error.withPrefix(key) 1309 } 1310 } 1311 1312 @inline(__always) 1313 internal func scoped
DecimalNumber.swift:154
            return try scoped(index) { try value.getDecimalNumber() }
DecimalNumber.swift:164
            return try scoped(index) { try value.getDecimalNumberOrNil() }
DecimalNumber.swift:176
            return try scoped(index) { try value.toDecimalNumber() }
DecimalNumber.swift:187
            return try scoped(index) { try value.toDecimalNumberOrNil() }
JSONError.swift:670
        return try scoped(index) { try value.getBool() }
JSONError.swift:680
        return try scoped(index) { try value.getBoolOrNil() }
JSONError.swift:691
        return try scoped(index) { try value.getString() }
JSONError.swift:701
        return try scoped(index) { try value.getStringOrNil() }
JSONError.swift:712
        return try scoped(index) { try value.getInt64() }
JSONError.swift:722
        return try scoped(index) { try value.getInt64OrNil() }
JSONError.swift:734
        return try scoped(index) { try value.getInt() }
JSONError.swift:745
        return try scoped(index) { try value.getIntOrNil() }
JSONError.swift:756
        return try scoped(index) { try value.getDouble() }
JSONError.swift:766
        return try scoped(index) { try value.getDoubleOrNil() }
JSONError.swift:801
        return try scoped(index) { try f(value.getObject()) }
JSONError.swift:813
        return try scoped(index) { try value.getObjectOrNil().flatMap(f) }
JSONError.swift:848
        return try scoped(index) { try f(value.getArray()) }
JSONError.swift:860
        return try scoped(index) { try value.getArrayOrNil().flatMap(f) }
JSONError.swift:874
        return try scoped(index) { try value.toString() }
JSONError.swift:885
        return try scoped(index) { try value.toStringOrNil() }
JSONError.swift:898
        return try scoped(index) { try value.toInt64() }
JSONError.swift:911
        return try scoped(index) { try value.toInt64OrNil() }
JSONError.swift:924
        return try scoped(index) { try value.toInt() }
JSONError.swift:937
        return try scoped(index) { try value.toIntOrNil() }
JSONError.swift:950
        return try scoped(index) { try value.toDouble() }
JSONError.swift:962
        return try scoped(index) { try value.toDoubleOrNil() }
JSONError.swift:1250
        return try array.enumerate().map({ i, elt in try scoped(i, f: { try transform(elt) }) })
JSONError.swift:1265
        return try array.enumerate().flatMap({ i, elt in try scoped(i, f: { try transform(elt) }) })
JSONError.swift:1283
            try scoped(i) {
<T>(index: Int, @noescape f: () throws -> T) throws -> T { 1314 do { 1315 return try f() 1316 } catch let error as JSONError { 1317 throw error.withPrefix("[\(index)]") 1318 } 1319 } 1320 1321 internal extension ContiguousArray { 1322 subscript
DecimalNumber.swift:163
            guard let value = array[safe: index] else { return nil }
DecimalNumber.swift:186
            guard let value = array[safe: index] else { return nil }
JSONError.swift:679
        guard let value = ary[safe: index] else { return nil }
JSONError.swift:700
        guard let value = ary[safe: index] else { return nil }
JSONError.swift:721
        guard let value = ary[safe: index] else { return nil }
JSONError.swift:744
        guard let value = ary[safe: index] else { return nil }
JSONError.swift:765
        guard let value = ary[safe: index] else { return nil }
JSONError.swift:812
        guard let value = ary[safe: index] else { return nil }
JSONError.swift:859
        guard let value = ary[safe: index] else { return nil }
JSONError.swift:884
        guard let value = ary[safe: index] else { return nil }
JSONError.swift:910
        guard let value = ary[safe: index] else { return nil }
JSONError.swift:936
        guard let value = ary[safe: index] else { return nil }
JSONError.swift:961
        guard let value = ary[safe: index] else { return nil }
JSONError.swift:1299
    guard let value = ary[safe: index] else { throw JSONError.MissingOrInvalidType(path: "[\(index)]", expected: .Required(type), actual: nil) }
(safe index: Int) -> Element? { 1323 guard index >= startIndex && index < endIndex else { return nil } 1324 return self[index] 1325 } 1326 } 1327