diff --git a/JAYSON.playground/Pages/Build.xcplaygroundpage/Contents.swift b/JAYSON.playground/Pages/Build.xcplaygroundpage/Contents.swift index c43cc80..db32c3e 100644 --- a/JAYSON.playground/Pages/Build.xcplaygroundpage/Contents.swift +++ b/JAYSON.playground/Pages/Build.xcplaygroundpage/Contents.swift @@ -3,21 +3,21 @@ import Foundation @testable import JAYSON -var jayson = JAYSON() -jayson["id"] = 18737649 -jayson["active"] = true -jayson["name"] = "muukii" +var json = JSON() +json["id"] = 18737649 +json["active"] = true +json["name"] = "muukii" -jayson["images"] = JAYSON([ +json["images"] = JSON([ "large" : "http://...foo", "medium" : "http://...foo", "small" : "http://...foo", ]) -let data: Data = try jayson.data(options: .prettyPrinted) +let data: Data = try json.data(options: .prettyPrinted) do { - let data = try jayson.data(options: .prettyPrinted) + let data = try json.data(options: .prettyPrinted) print(String(data: data, encoding: .utf8)!) } catch { print(error) diff --git a/JAYSON.playground/Pages/Dribbble.xcplaygroundpage/Contents.swift b/JAYSON.playground/Pages/Dribbble.xcplaygroundpage/Contents.swift index 9187cd3..ba2e11b 100644 --- a/JAYSON.playground/Pages/Dribbble.xcplaygroundpage/Contents.swift +++ b/JAYSON.playground/Pages/Dribbble.xcplaygroundpage/Contents.swift @@ -5,10 +5,10 @@ import Foundation let dataPath = Bundle.main.path(forResource: "Sample", ofType: "json") let data = Data(referencing: NSData(contentsOfFile: dataPath!)!) -let jayson = try! JAYSON(data: data) +let json = try! JSON(data: data) -let urlDecoder = Decoder { (jayson) throws -> URL in - URL(string: try jayson.getString())! // You can throw custom error. +let urlDecoder = Decoder { (json) throws -> URL in + URL(string: try json.getString())! // You can throw custom error. } struct Shot { @@ -20,13 +20,13 @@ struct Shot { let normalImageURLString: URL let teaserImageURLString: URL - init(jayson: JAYSON) throws { - let imagesJayson = try jayson.next("images") + init(json: JSON) throws { + let imagesJayson = try json.next("images") - id = try jayson.next("id").getInt() - title = try jayson.next("title").getString() - width = try jayson.next("width").getInt() - height = try jayson.next("height").getInt() + id = try json.next("id").getInt() + title = try json.next("title").getString() + width = try json.next("width").getInt() + height = try json.next("height").getInt() hidpiImageURLString = try? imagesJayson.next("hidpi").get(with: urlDecoder) normalImageURLString = try imagesJayson.next("normal").get(with: urlDecoder) teaserImageURLString = try imagesJayson.next("teaser").get(with: urlDecoder) @@ -34,7 +34,7 @@ struct Shot { } do { - let shots: [Shot] = try jayson.getArray().map(Shot.init(jayson: )) + let shots: [Shot] = try json.getArray().map(Shot.init(json: )) print(shots) } catch { print(error) diff --git a/JAYSON.playground/Pages/Test.xcplaygroundpage/Contents.swift b/JAYSON.playground/Pages/Test.xcplaygroundpage/Contents.swift index 5e93df4..13158f7 100644 --- a/JAYSON.playground/Pages/Test.xcplaygroundpage/Contents.swift +++ b/JAYSON.playground/Pages/Test.xcplaygroundpage/Contents.swift @@ -6,29 +6,29 @@ import JAYSON let dataPath = Bundle.main.path(forResource: "test", ofType: "json") let data = Data(referencing: NSData(contentsOfFile: dataPath!)!) -let jayson = try! JAYSON(data) +let JSON = try! JSON(data) -let urlTransformer = Decoder { (jayson) throws -> URL in - URL(string: try jayson.getString())! +let urlTransformer = Decoder { (JSON) throws -> URL in + URL(string: try JSON.getString())! } do { - let fooJayson = try jayson + let fooJSON = try JSON .next("tree1") .next("tree2") .next("tree3") .next(0) .next("index") - let value = try fooJayson.getString() - let path = fooJayson.currentPath() + let value = try fooJSON.getString() + let path = fooJSON.currentPath() - let url = try jayson + let url = try JSON .next("url") .get(with: urlTransformer) - let null = try jayson.next("null") + let null = try JSON.next("null") null.isNull do { @@ -48,7 +48,7 @@ do { do { - let fooJayson = try jayson + let fooJSON = try JSON .next("tree1") .next("tree2") .back() diff --git a/JAYSON.playground/Pages/Untitled Page.xcplaygroundpage/Contents.swift b/JAYSON.playground/Pages/Untitled Page.xcplaygroundpage/Contents.swift index ed14d57..f140647 100644 --- a/JAYSON.playground/Pages/Untitled Page.xcplaygroundpage/Contents.swift +++ b/JAYSON.playground/Pages/Untitled Page.xcplaygroundpage/Contents.swift @@ -1,17 +1,17 @@ //: [Previous](@previous) import Foundation -@testable import JAYSON +@testable import JSON let dataPath = Bundle.main.path(forResource: "unsplash", ofType: "json") let inData = Data(referencing: NSData(contentsOfFile: dataPath!)!) -let jayson = try JAYSON(data: inData) +let JSON = try JSON(data: inData) -//print(jayson) -//debugPrint(jayson) +//print(JSON) +//debugPrint(JSON) do { - let urlString: String = try jayson + let urlString: String = try JSON .next("shots") .next(0) .next("user") @@ -19,28 +19,28 @@ do { .next("large") .getString() - let shots = try jayson.next("shots").getArray().map { try $0.next("id").getString() } + let shots = try JSON.next("shots").getArray().map { try $0.next("id").getString() } print(shots) } catch { print(error) } -let urlString: String? = jayson["shots"][0]["user"]["profile_image"]["large"].string +let urlString: String? = JSON["shots"][0]["user"]["profile_image"]["large"].string -let shots = jayson["shots"].array?.map { $0["id"].string } +let shots = JSON["shots"].array?.map { $0["id"].string } -let large = jayson["shots"][0]["user"]["profile_image"]["large"] +let large = JSON["shots"][0]["user"]["profile_image"]["large"] print(large.currentPath()) print(shots) -let urlDecoder = Decoder { (jayson) throws -> URL in - URL(string: try jayson.getString())! +let urlDecoder = Decoder { (JSON) throws -> URL in + URL(string: try JSON.getString())! } -try! jayson +try! JSON .next("shots") .next(0) .next("user") @@ -49,18 +49,18 @@ try! jayson .get(with: urlDecoder) -try! jayson +try! JSON .next("shots") .next(0) .next("user") .next("profile_image") .next("large") - .get { (jayson) throws -> URL in - URL(string: try jayson.getString())! + .get { (JSON) throws -> URL in + URL(string: try JSON.getString())! } do { - let urlString: String = try jayson + let urlString: String = try JSON .next("shots") .next(0) .next("user") diff --git a/Sources/Decoder.swift b/Sources/Decoder.swift index a3f8c7e..7ab528c 100644 --- a/Sources/Decoder.swift +++ b/Sources/Decoder.swift @@ -22,9 +22,9 @@ public struct Decoder { - let decode: (JAYSON) throws -> T + let decode: (JSON) throws -> T - public init(_ s: @escaping (JAYSON) throws -> T) { + public init(_ s: @escaping (JSON) throws -> T) { self.decode = s } } diff --git a/Sources/JAYSON+OptionalProperty.swift b/Sources/JAYSON+OptionalProperty.swift index 94c99cf..837315c 100644 --- a/Sources/JAYSON+OptionalProperty.swift +++ b/Sources/JAYSON+OptionalProperty.swift @@ -1,4 +1,4 @@ -// JAYSON+OptionalProperty.swift +// JSON+OptionalProperty.swift // // Copyright (c) 2016 muukii // @@ -22,20 +22,20 @@ import Foundation -extension JAYSON { +extension JSON { - public var dictionary: [String : JAYSON]? { - return (source as? [String : Any])?.reduce([String : JAYSON]()) { dic, element in + public var dictionary: [String : JSON]? { + return (source as? [String : Any])?.reduce([String : JSON]()) { dic, element in var dic = dic - dic[element.key] = JAYSON(source: element.value, breadcrumb: Breadcrumb(jayson: self, key: element.key)) + dic[element.key] = JSON(source: element.value, breadcrumb: Breadcrumb(json: self, key: element.key)) return dic } } - public var array: [JAYSON]? { + public var array: [JSON]? { return (source as? [Any])? .enumerated() - .map { JAYSON(source: $0.element, breadcrumb: Breadcrumb(jayson: self, index: $0.offset)) } + .map { JSON(source: $0.element, breadcrumb: Breadcrumb(json: self, index: $0.offset)) } } public var string: String? { @@ -106,7 +106,7 @@ extension JAYSON { } } - public func getOrNil(_ s: (JAYSON) throws -> T) -> T? { + public func getOrNil(_ s: (JSON) throws -> T) -> T? { do { return try s(self) } catch { diff --git a/Sources/JAYSON+SourceType.swift b/Sources/JAYSON+SourceType.swift index 718ac50..ac75b4b 100644 --- a/Sources/JAYSON+SourceType.swift +++ b/Sources/JAYSON+SourceType.swift @@ -1,4 +1,4 @@ -// JAYSON+SourceType.swift +// JSON+SourceType.swift // // Copyright (c) 2016 muukii // @@ -22,7 +22,7 @@ import Foundation -extension JAYSON { +extension JSON { public enum SourceType { diff --git a/Sources/JAYSON+StateProperty.swift b/Sources/JAYSON+StateProperty.swift index 134a29c..855c97c 100644 --- a/Sources/JAYSON+StateProperty.swift +++ b/Sources/JAYSON+StateProperty.swift @@ -1,4 +1,4 @@ -// JAYSON+StateProperty.swift +// JSON+StateProperty.swift // // Copyright (c) 2016 muukii // @@ -22,7 +22,7 @@ import Foundation -extension JAYSON { +extension JSON { public var isNull: Bool { if case .null = sourceType { diff --git a/Sources/JAYSON+StrictGetter.swift b/Sources/JAYSON+StrictGetter.swift index 66becf9..4e5b274 100644 --- a/Sources/JAYSON+StrictGetter.swift +++ b/Sources/JAYSON+StrictGetter.swift @@ -1,4 +1,4 @@ -// JAYSON+StrictGetter.swift +// JSON+StrictGetter.swift // // Copyright (c) 2016 muukii // @@ -23,25 +23,25 @@ import Foundation // Get Swift Value -extension JAYSON { +extension JSON { - public func getDictionary() throws -> [String : JAYSON] { + public func getDictionary() throws -> [String : JSON] { guard let value = dictionary else { - throw JAYSONError.failedToGetDictionary(source: source, jayson: self) + throw JSONError.failedToGetDictionary(source: source, json: self) } return value } - public func getArray() throws -> [JAYSON] { + public func getArray() throws -> [JSON] { guard let value = array else { - throw JAYSONError.failedToGetArray(source: source, jayson: self) + throw JSONError.failedToGetArray(source: source, json: self) } return value } public func getNumber() throws -> NSNumber { guard let value = number else { - throw JAYSONError.failedToGetNumber(source: source, jayson: self) + throw JSONError.failedToGetNumber(source: source, json: self) } return value } @@ -88,14 +88,14 @@ extension JAYSON { public func getString() throws -> String { guard let value = string else { - throw JAYSONError.failedToGetString(source: source, jayson: self) + throw JSONError.failedToGetString(source: source, json: self) } return value } public func getBool() throws -> Bool { guard let value = source as? Bool else { - throw JAYSONError.failedToGetBool(source: source, jayson: self) + throw JSONError.failedToGetBool(source: source, json: self) } return value } @@ -108,23 +108,23 @@ extension JAYSON { return try getNumber().doubleValue } - public func get(_ s: (JAYSON) throws -> T) rethrows -> T { + public func get(_ s: (JSON) throws -> T) rethrows -> T { do { return try s(self) - } catch let jaysonError as JAYSONError { - throw jaysonError + } catch let jsonError as JSONError { + throw jsonError } catch { - throw JAYSONError.decodeError(source: source, jayson: self, decodeError: error) + throw JSONError.decodeError(source: source, json: self, decodeError: error) } } public func get(with decoder: Decoder) throws -> T { do { return try decoder.decode(self) - } catch let jaysonError as JAYSONError { - throw jaysonError + } catch let jsonError as JSONError { + throw jsonError } catch { - throw JAYSONError.decodeError(source: source, jayson: self, decodeError: error) + throw JSONError.decodeError(source: source, json: self, decodeError: error) } } diff --git a/Sources/JAYSON.swift b/Sources/JAYSON.swift index 00e4351..0ec48f9 100644 --- a/Sources/JAYSON.swift +++ b/Sources/JAYSON.swift @@ -1,4 +1,4 @@ -// JAYSON.swift +// JSON.swift // // Copyright (c) 2016 muukii // @@ -20,48 +20,51 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. +@available(*, deprecated: 1.0.0, message: "Use `JSON`") +public typealias JAYSON = JSON + import Foundation -public enum JAYSONError: Error { - case notFoundKey(key: String, jayson: JAYSON) - case notFoundIndex(index: Int, jayson: JAYSON) - case failedToGetString(source: Any, jayson: JAYSON) - case failedToGetBool(source: Any, jayson: JAYSON) - case failedToGetNumber(source: Any, jayson: JAYSON) - case failedToGetArray(source: Any, jayson: JAYSON) - case failedToGetDictionary(source: Any, jayson: JAYSON) - case decodeError(source: Any, jayson: JAYSON, decodeError: Error) +public enum JSONError: Error { + case notFoundKey(key: String, json: JSON) + case notFoundIndex(index: Int, json: JSON) + case failedToGetString(source: Any, json: JSON) + case failedToGetBool(source: Any, json: JSON) + case failedToGetNumber(source: Any, json: JSON) + case failedToGetArray(source: Any, json: JSON) + case failedToGetDictionary(source: Any, json: JSON) + case decodeError(source: Any, json: JSON, decodeError: Error) case invalidJSONObject } -public struct JAYSON: CustomDebugStringConvertible, Equatable { +public struct JSON: CustomDebugStringConvertible, Equatable { - public static func ==(lhs: JAYSON, rhs: JAYSON) -> Bool { + public static func ==(lhs: JSON, rhs: JSON) -> Bool { return (lhs.source as? NSObject) == (rhs.source as? NSObject) } - public static let null = JAYSON() + public static let null = JSON() public fileprivate(set) var source: Any fileprivate let breadcrumb: Breadcrumb? - public init(_ object: JAYSONWritableType) { + public init(_ object: JSONWritableType) { source = object.jsonValueBox.source breadcrumb = nil } - public init(_ object: [JAYSONWritableType]) { + public init(_ object: [JSONWritableType]) { source = object.map { $0.jsonValueBox.source } breadcrumb = nil } - public init(_ object: [JAYSON]) { + public init(_ object: [JSON]) { source = object.map { $0.source } breadcrumb = nil } - public init(_ object: [String : JAYSON]) { + public init(_ object: [String : JSON]) { source = object.reduce([String : Any]()) { dictionary, object in var dictionary = dictionary dictionary[object.key] = object.value.source @@ -70,7 +73,7 @@ public struct JAYSON: CustomDebugStringConvertible, Equatable { breadcrumb = nil } - public init(_ object: [String : JAYSONWritableType]) { + public init(_ object: [String : JSONWritableType]) { source = object.reduce([String : Any]()) { dic, element in var dic = dic dic[element.key] = element.value.jsonValueBox.source @@ -91,7 +94,7 @@ public struct JAYSON: CustomDebugStringConvertible, Equatable { public init(any: Any) throws { guard JSONSerialization.isValidJSONObject(any) else { - throw JAYSONError.invalidJSONObject + throw JSONError.invalidJSONObject } self.init(source: any, breadcrumb: nil) } @@ -103,7 +106,7 @@ public struct JAYSON: CustomDebugStringConvertible, Equatable { public func data(options: JSONSerialization.WritingOptions = []) throws -> Data { guard JSONSerialization.isValidJSONObject(source) else { - throw JAYSONError.invalidJSONObject + throw JSONError.invalidJSONObject } return try JSONSerialization.data(withJSONObject: source, options: options) } @@ -116,7 +119,7 @@ public struct JAYSON: CustomDebugStringConvertible, Equatable { while let _currentBreadcrumb = currentBreadcrumb { path = _currentBreadcrumb.path + path - currentBreadcrumb = _currentBreadcrumb.jayson.breadcrumb + currentBreadcrumb = _currentBreadcrumb.json.breadcrumb } return "Root->" + path @@ -124,7 +127,7 @@ public struct JAYSON: CustomDebugStringConvertible, Equatable { public var debugDescription: String { return "\n" - + "JAYSON\n" + + "JSON\n" + "Path: \(currentPath())\n" + "SourceType: \(sourceType)\n" + "\n" @@ -132,20 +135,20 @@ public struct JAYSON: CustomDebugStringConvertible, Equatable { } } -extension JAYSON { +extension JSON { final class Breadcrumb: CustomStringConvertible, CustomDebugStringConvertible { - let jayson: JAYSON + let json: JSON let path: String - init(jayson: JAYSON, key: String) { - self.jayson = jayson + init(json: JSON, key: String) { + self.json = json self.path = "[\"\(key)\"]" } - init(jayson: JAYSON, index: Int) { - self.jayson = jayson + init(json: JSON, index: Int) { + self.json = json self.path = "[\(index)]" } @@ -154,19 +157,19 @@ extension JAYSON { } var debugDescription: String { - return "\(path)\n\(jayson)" + return "\(path)\n\(json)" } } } -extension JAYSON { +extension JSON { - /// if key is not found, return JAYSON.null - public subscript (key: String) -> JAYSON { + /// if key is not found, return JSON.null + public subscript (key: String) -> JSON { get { return (source as? NSDictionary) .flatMap { $0[key] } - .map { JAYSON(source: $0, breadcrumb: Breadcrumb(jayson: self, key: key)) } ?? JAYSON.null + .map { JSON(source: $0, breadcrumb: Breadcrumb(json: self, key: key)) } ?? JSON.null } set { if source is NSNull { @@ -181,8 +184,8 @@ extension JAYSON { } } - /// if index is not found return JAYSON.null - public subscript (index: Int) -> JAYSON { + /// if index is not found return JSON.null + public subscript (index: Int) -> JSON { get { return (source as? NSArray) .flatMap { @@ -191,7 +194,7 @@ extension JAYSON { } return nil } - .map { JAYSON(source: $0, breadcrumb: Breadcrumb(jayson: self, index: index)) } ?? JAYSON.null + .map { JSON(source: $0, breadcrumb: Breadcrumb(json: self, index: index)) } ?? JSON.null } /* set { @@ -215,68 +218,68 @@ extension JAYSON { } } -/// Control JAYSON hierarchy -extension JAYSON { +/// Control JSON hierarchy +extension JSON { - private func _next(_ key: String) throws -> JAYSON { + private func _next(_ key: String) throws -> JSON { return try key.characters .split(separator: ".") .map { String($0) } .reduce(self) { j, key in guard !(j[key].source is NSNull) else { - throw JAYSONError.notFoundKey(key: key, jayson: self) + throw JSONError.notFoundKey(key: key, json: self) } return j[key] } } - private func _next(_ keys: [String]) throws -> JAYSON { - return try keys.reduce(self) { jayson, key -> JAYSON in - try jayson._next(key) + private func _next(_ keys: [String]) throws -> JSON { + return try keys.reduce(self) { json, key -> JSON in + try json._next(key) } } /** - if `type` is `Dictonary`, return `JAYSON` whose object is `dictionary[key]`, otherwise throw `JAYSONError`. + if `type` is `Dictonary`, return `JSON` whose object is `dictionary[key]`, otherwise throw `JSONError`. e.g next("a", "b", "c") or next("a.b.c") */ - public func next(_ key: String...) throws -> JAYSON { + public func next(_ key: String...) throws -> JSON { return try _next(key) } - public func next(_ key: T) throws -> JAYSON where T.RawValue == String { + public func next(_ key: T) throws -> JSON where T.RawValue == String { return try _next(key.rawValue) } /** - if `type` is `Array`, return `JAYSON` whose object is `array[index]`, otherwise throw `JAYSONError`. + if `type` is `Array`, return `JSON` whose object is `array[index]`, otherwise throw `JSONError`. */ - public func next(_ index: Int) throws -> JAYSON { + public func next(_ index: Int) throws -> JSON { guard !(self[index].source is NSNull) else { - throw JAYSONError.notFoundIndex(index: index, jayson: self) + throw JSONError.notFoundIndex(index: index, json: self) } return self[index] } - public func next(_ key: T) throws -> JAYSON where T.RawValue == Int { + public func next(_ key: T) throws -> JSON where T.RawValue == Int { return try next(key.rawValue) } /** - if `self` has parent JAYSON, return parent `JAYSON`, otherwise return `self` + if `self` has parent JSON, return parent `JSON`, otherwise return `self` */ - public func back() -> JAYSON { - return breadcrumb?.jayson ?? self + public func back() -> JSON { + return breadcrumb?.json ?? self } - public func removed(_ key: String) -> JAYSON { + public func removed(_ key: String) -> JSON { guard let _source = (source as? NSDictionary)?.mutableCopy() as? NSMutableDictionary else { return self } _source.removeObject(forKey: key) - return try! JAYSON(any: _source) + return try! JSON(any: _source) } public func exists(_ key: String...) -> Bool { @@ -304,13 +307,13 @@ extension JAYSON { } } -extension JAYSON: Swift.ExpressibleByNilLiteral { +extension JSON: Swift.ExpressibleByNilLiteral { public init(nilLiteral: ()) { self.init() } } -extension JAYSON: Swift.ExpressibleByStringLiteral { +extension JSON: Swift.ExpressibleByStringLiteral { public init(stringLiteral value: StringLiteralType) { self.init(value) @@ -325,31 +328,31 @@ extension JAYSON: Swift.ExpressibleByStringLiteral { } } -extension JAYSON: Swift.ExpressibleByIntegerLiteral { +extension JSON: Swift.ExpressibleByIntegerLiteral { public init(integerLiteral value: IntegerLiteralType) { self.init(value) } } -extension JAYSON: Swift.ExpressibleByBooleanLiteral { +extension JSON: Swift.ExpressibleByBooleanLiteral { public init(booleanLiteral value: BooleanLiteralType) { self.init(value) } } -extension JAYSON: Swift.ExpressibleByFloatLiteral { +extension JSON: Swift.ExpressibleByFloatLiteral { public init(floatLiteral value: FloatLiteralType) { self.init(value) } } -extension JAYSON: Swift.ExpressibleByDictionaryLiteral { +extension JSON: Swift.ExpressibleByDictionaryLiteral { - public init(dictionaryLiteral elements: (String, JAYSON)...) { - let dictionary = elements.reduce([String : JAYSON]()) { dic, element in + public init(dictionaryLiteral elements: (String, JSON)...) { + let dictionary = elements.reduce([String : JSON]()) { dic, element in var dic = dic dic[element.0] = element.1 return dic @@ -358,8 +361,8 @@ extension JAYSON: Swift.ExpressibleByDictionaryLiteral { } } -extension JAYSON: Swift.ExpressibleByArrayLiteral { - public init(arrayLiteral elements: JAYSON...) { +extension JSON: Swift.ExpressibleByArrayLiteral { + public init(arrayLiteral elements: JSON...) { self.init(elements) } } diff --git a/Sources/JAYSONWritableType.swift b/Sources/JAYSONWritableType.swift index ebfe372..51498b4 100644 --- a/Sources/JAYSONWritableType.swift +++ b/Sources/JAYSONWritableType.swift @@ -22,7 +22,7 @@ import Foundation -public struct JAYSONValueBox { +public struct JSONValueBox { public let source: Any @@ -59,110 +59,110 @@ public struct JAYSONValueBox { } } -public protocol JAYSONWritableType { +public protocol JSONWritableType { - var jsonValueBox: JAYSONValueBox { get } + var jsonValueBox: JSONValueBox { get } } -extension NSNull: JAYSONWritableType { - public var jsonValueBox: JAYSONValueBox { - return JAYSONValueBox(self) +extension NSNull: JSONWritableType { + public var jsonValueBox: JSONValueBox { + return JSONValueBox(self) } } -extension String: JAYSONWritableType { - public var jsonValueBox: JAYSONValueBox { - return JAYSONValueBox(self) +extension String: JSONWritableType { + public var jsonValueBox: JSONValueBox { + return JSONValueBox(self) } } -extension NSString: JAYSONWritableType { - public var jsonValueBox: JAYSONValueBox { - return JAYSONValueBox(self) +extension NSString: JSONWritableType { + public var jsonValueBox: JSONValueBox { + return JSONValueBox(self) } } -extension NSNumber: JAYSONWritableType { - public var jsonValueBox: JAYSONValueBox { - return JAYSONValueBox(self) +extension NSNumber: JSONWritableType { + public var jsonValueBox: JSONValueBox { + return JSONValueBox(self) } } -extension Int: JAYSONWritableType { - public var jsonValueBox: JAYSONValueBox { - return JAYSONValueBox(self) +extension Int: JSONWritableType { + public var jsonValueBox: JSONValueBox { + return JSONValueBox(self) } } -extension Float: JAYSONWritableType { - public var jsonValueBox: JAYSONValueBox { - return JAYSONValueBox(self) +extension Float: JSONWritableType { + public var jsonValueBox: JSONValueBox { + return JSONValueBox(self) } } -extension Double: JAYSONWritableType { - public var jsonValueBox: JAYSONValueBox { - return JAYSONValueBox(self) +extension Double: JSONWritableType { + public var jsonValueBox: JSONValueBox { + return JSONValueBox(self) } } -extension Bool: JAYSONWritableType { - public var jsonValueBox: JAYSONValueBox { - return JAYSONValueBox(self) +extension Bool: JSONWritableType { + public var jsonValueBox: JSONValueBox { + return JSONValueBox(self) } } -extension Int8: JAYSONWritableType { - public var jsonValueBox: JAYSONValueBox { - return JAYSONValueBox(NSNumber(value: self)) +extension Int8: JSONWritableType { + public var jsonValueBox: JSONValueBox { + return JSONValueBox(NSNumber(value: self)) } } -extension Int16: JAYSONWritableType { - public var jsonValueBox: JAYSONValueBox { - return JAYSONValueBox(NSNumber(value: self)) +extension Int16: JSONWritableType { + public var jsonValueBox: JSONValueBox { + return JSONValueBox(NSNumber(value: self)) } } -extension Int32: JAYSONWritableType { - public var jsonValueBox: JAYSONValueBox { - return JAYSONValueBox(NSNumber(value: self)) +extension Int32: JSONWritableType { + public var jsonValueBox: JSONValueBox { + return JSONValueBox(NSNumber(value: self)) } } -extension Int64: JAYSONWritableType { - public var jsonValueBox: JAYSONValueBox { - return JAYSONValueBox(NSNumber(value: self)) +extension Int64: JSONWritableType { + public var jsonValueBox: JSONValueBox { + return JSONValueBox(NSNumber(value: self)) } } -extension UInt: JAYSONWritableType { - public var jsonValueBox: JAYSONValueBox { - return JAYSONValueBox(NSNumber(value: self)) +extension UInt: JSONWritableType { + public var jsonValueBox: JSONValueBox { + return JSONValueBox(NSNumber(value: self)) } } -extension UInt8: JAYSONWritableType { - public var jsonValueBox: JAYSONValueBox { - return JAYSONValueBox(NSNumber(value: self)) +extension UInt8: JSONWritableType { + public var jsonValueBox: JSONValueBox { + return JSONValueBox(NSNumber(value: self)) } } -extension UInt16: JAYSONWritableType { - public var jsonValueBox: JAYSONValueBox { - return JAYSONValueBox(NSNumber(value: self)) +extension UInt16: JSONWritableType { + public var jsonValueBox: JSONValueBox { + return JSONValueBox(NSNumber(value: self)) } } -extension UInt32: JAYSONWritableType { - public var jsonValueBox: JAYSONValueBox { - return JAYSONValueBox(NSNumber(value: self)) +extension UInt32: JSONWritableType { + public var jsonValueBox: JSONValueBox { + return JSONValueBox(NSNumber(value: self)) } } -extension UInt64: JAYSONWritableType { - public var jsonValueBox: JAYSONValueBox { - return JAYSONValueBox(NSNumber(value: self)) +extension UInt64: JSONWritableType { + public var jsonValueBox: JSONValueBox { + return JSONValueBox(NSNumber(value: self)) } } @@ -173,9 +173,9 @@ extension UInt64: JAYSONWritableType { import UIKit #endif - extension CGFloat: JAYSONWritableType { - public var jsonValueBox: JAYSONValueBox { - return JAYSONValueBox(self as NSNumber) + extension CGFloat: JSONWritableType { + public var jsonValueBox: JSONValueBox { + return JSONValueBox(self as NSNumber) } } #endif diff --git a/Tests/BasicTests/DribbbleImportTests.swift b/Tests/BasicTests/DribbbleImportTests.swift index 594d06a..f069b77 100644 --- a/Tests/BasicTests/DribbbleImportTests.swift +++ b/Tests/BasicTests/DribbbleImportTests.swift @@ -1,6 +1,6 @@ // // DribbbleImportTests.swift -// JAYSON +// JSON // // Created by muukii on 9/18/16. // Copyright © 2016 CocoaPods. All rights reserved. @@ -28,19 +28,19 @@ class DribbbleImportTests: XCTestCase { func testImport() { do { - let jayson = try JAYSON(data: data) + let json = try JSON(data: data) - let shots: [Shot] = try jayson.getArray().map { jayson -> Shot in + let shots: [Shot] = try json.getArray().map { json -> Shot in - let imagesJayson = try jayson.next("images") + let imagesJayson = try json.next("images") - // print(try jayson.next("images", "normal").currentPath()) + // print(try json.next("images", "normal").currentPath()) return Shot( - id: try jayson.next("id").getInt(), - title: try jayson.next("title").getString(), - width: try jayson.next("width").getInt(), - height: try jayson.next("height").getInt(), + id: try json.next("id").getInt(), + title: try json.next("title").getString(), + width: try json.next("width").getInt(), + height: try json.next("height").getInt(), hidpiImageURLString: try? imagesJayson.next("hidpi").getString(), normalImageURLString: try imagesJayson.next("normal").getString(), teaserImageURLString: try imagesJayson.next("teaser").getString() diff --git a/Tests/BasicTests/Tests.swift b/Tests/BasicTests/Tests.swift index b3f5e41..eadc87f 100644 --- a/Tests/BasicTests/Tests.swift +++ b/Tests/BasicTests/Tests.swift @@ -22,31 +22,31 @@ class Tests: XCTestCase { case b case c - var jayson: JAYSON { + var json: JSON { switch self { case .a: - return JAYSON("a") + return JSON("a") case .b: - return JAYSON("b") + return JSON("b") case .c: - return JAYSON("c") + return JSON("c") } } } func testEqualable() { - let source: [String : JAYSON] = [ + let source: [String : JSON] = [ "aaa":"AAA", "bbb":["BBB":"AAA"], "a":[1,2,3], - "enum":Enum.a.jayson, + "enum":Enum.a.json, ] - let jayson = JAYSON(source) - let jayson2 = JAYSON(source) + let json = JSON(source) + let json2 = JSON(source) - XCTAssert(jayson == jayson2) + XCTAssert(json == json2) } func testDictionaryInit() { @@ -59,9 +59,9 @@ class Tests: XCTestCase { ] do { - let jayson = try JAYSON(any: dictionary) - let data = try jayson.data() - _ = try JAYSON(data: data) + let json = try JSON(any: dictionary) + let data = try json.data() + _ = try JSON(data: data) } catch { XCTFail("\(error)") } @@ -69,28 +69,28 @@ class Tests: XCTestCase { func testIsArray() { - let jayson = JAYSON([ + let json = JSON([ 128,129,130, ]) - XCTAssert(jayson.isArray) + XCTAssert(json.isArray) } func testIsDictionary() { - let jayson = JAYSON( + let json = JSON( [ "aaa":"AAA", "bbb":["BBB":"AAA"], "a":[1,2,3], - "enum":Enum.a.jayson, + "enum":Enum.a.json, ] ) - XCTAssert(jayson.isDictionary) + XCTAssert(json.isDictionary) } func testExists() { - let j = try! JAYSON(data: inData) + let j = try! JSON(data: inData) XCTAssert(j.exists(13) == false) XCTAssert(j.exists("a") == false) @@ -104,7 +104,7 @@ class Tests: XCTestCase { func testNext() { do { - let j = try JAYSON(data: inData) + let j = try JSON(data: inData) let v = j["a"]["b"][1] XCTAssert(v.isNull) } catch { @@ -112,7 +112,7 @@ class Tests: XCTestCase { } do { - let j = try JAYSON(data: inData) + let j = try JSON(data: inData) do { let v = try j.next("a").next("b").next("c") @@ -126,7 +126,7 @@ class Tests: XCTestCase { do { - let j = try JAYSON(data: inData) + let j = try JSON(data: inData) let v = try j.next("tree1.tree2.tree3").next(0).next("index") XCTAssertEqual(v, "myvalue") } catch { @@ -135,7 +135,7 @@ class Tests: XCTestCase { } func testRemove() { - let j = try! JAYSON(data: inData) + let j = try! JSON(data: inData) let removed = j.removed("tree1") XCTAssert(j["tree1"] != nil) @@ -146,7 +146,7 @@ class Tests: XCTestCase { func testImportExport() { do { - let j = try JAYSON(data: inData) + let j = try JSON(data: inData) let data = try j.data() } catch { XCTFail("\(error)") @@ -156,7 +156,7 @@ class Tests: XCTestCase { func testBack() { do { - let j = try JAYSON(data: inData) + let j = try JSON(data: inData) let value = try j .next("tree1") .next("tree2") @@ -178,18 +178,18 @@ class Tests: XCTestCase { } func testBuild() { - var j = JAYSON() + var j = JSON() j["number"] = 124 j["text"] = "hooo" j["bool"] = true - j["null"] = JAYSON.null - j["tree1"] = JAYSON( + j["null"] = JSON.null + j["tree1"] = JSON( [ - "tree2" : JAYSON( + "tree2" : JSON( [ - "tree3" : JAYSON( + "tree3" : JSON( [ - JAYSON(["index" : "myvalue"]) + JSON(["index" : "myvalue"]) ] ) ] @@ -209,38 +209,38 @@ class Tests: XCTestCase { func testJSONWritable() { - var jayson = JAYSON() + var json = JSON() - jayson["String"] = "String" - jayson["NSString"] = JAYSON("NSString" as NSString) - jayson["Int"] = 64 - jayson["Int8"] = JAYSON(8 as Int8) - jayson["Int16"] = JAYSON(16 as Int16) - jayson["Int32"] = JAYSON(32 as Int32) - jayson["Int64"] = JAYSON(64 as Int64) + json["String"] = "String" + json["NSString"] = JSON("NSString" as NSString) + json["Int"] = 64 + json["Int8"] = JSON(8 as Int8) + json["Int16"] = JSON(16 as Int16) + json["Int32"] = JSON(32 as Int32) + json["Int64"] = JSON(64 as Int64) - jayson["UInt"] = JAYSON(64 as UInt) - jayson["UInt8"] = JAYSON(8 as UInt8) - jayson["UInt16"] = JAYSON(16 as UInt16) - jayson["UInt32"] = JAYSON(32 as UInt32) - jayson["UInt64"] = JAYSON(64 as UInt64) + json["UInt"] = JSON(64 as UInt) + json["UInt8"] = JSON(8 as UInt8) + json["UInt16"] = JSON(16 as UInt16) + json["UInt32"] = JSON(32 as UInt32) + json["UInt64"] = JSON(64 as UInt64) - jayson["Bool_true"] = true - jayson["Bool_false"] = false + json["Bool_true"] = true + json["Bool_false"] = false - jayson["Float"] = JAYSON(1.0 / 3.0 as Float) - jayson["Double"] = JAYSON(1.0 / 3.0 as Double) + json["Float"] = JSON(1.0 / 3.0 as Float) + json["Double"] = JSON(1.0 / 3.0 as Double) #if !os(Linux) - jayson["CGFloat"] = JAYSON(1.0 / 3.0 as CGFloat) + json["CGFloat"] = JSON(1.0 / 3.0 as CGFloat) let answer = "{\"UInt8\":8,\"Int32\":32,\"UInt\":64,\"UInt16\":16,\"UInt32\":32,\"Int16\":16,\"Int\":64,\"String\":\"String\",\"CGFloat\":0.3333333333333333,\"Int8\":8,\"UInt64\":64,\"Float\":0.3333333,\"Double\":0.3333333333333333,\"Bool_true\":true,\"Int64\":64,\"Bool_false\":false,\"NSString\":\"NSString\"}" - print(String(data: try! jayson.data(), encoding: .utf8)) - let value = String(data: try! jayson.data(), encoding: .utf8)! + print(String(data: try! json.data(), encoding: .utf8)) + let value = String(data: try! json.data(), encoding: .utf8)! XCTAssert(answer == value) #else let answer = "{\"UInt8\":8,\"Int32\":32,\"UInt\":64,\"UInt16\":16,\"UInt32\":32,\"Int16\":16,\"Int\":64,\"String\":\"String\",\"Int8\":8,\"UInt64\":64,\"Float\":0.3333333,\"Double\":0.3333333333333333,\"Bool_true\":true,\"Int64\":64,\"Bool_false\":false,\"NSString\":\"NSString\"}" - print(String(data: try! jayson.data(), encoding: .utf8)) - let value = String(data: try! jayson.data(), encoding: .utf8)! + print(String(data: try! json.data(), encoding: .utf8)) + let value = String(data: try! json.data(), encoding: .utf8)! XCTAssert(answer == value) #endif