Swiftpack.co - Package - Beyova/BeyovaJSON

BeyovaJSON

Travis CI Carthage Compatible CocoaPods Swift

BeyovaJSON makes it easier to deal with JSON and Coadable in Swift 4. Inspired by SwiftyJSON

Installation

CocoaPods

pod 'BeyovaJSON'

Carthage

github "Beyova/BeyovaJSON"

Usage

import BeyovaJSON

Getter

let users = JToken(rawData: dataFromNetworking)
if let name = users[0]["name"].string {
	//got the name
}

Boundary check for conversion in Swift is kept:

let value: JToken = 9999
print(value.int8Value) // fatal error

Setter

let users = JToken(rawData: dataFromNetworking)
users[0]["name"] = JToken.init("John")

Expressible

let users: JToken = [["name": "Tom"],["name": "Jerry"]]
users[0]["name"] = "John"

Codable

Codable is added with Xcode 9, iOS 11 and Swift 4. It is used to make your data types encodable and decodable for compatibility with external representations such as JSON.

Date and Data are also supported by BeyovaJSON in line with Codable.

class Group: Codable {
	var title: String = "Guardians of the Galaxy"
	var users: JToken = [["name": "Star-Lord"],["name": "Groot"],["name": "Rocket"]]
	var date: Date = Date()
}
let group = Group()
let encoder = JSONEncoder()
encoder.outputFormatting = .prettyPrinted
let data = try! encoder.encode(group)
print(String(bytes: data, encoding: .utf8)!)

Github

link
Stars: 4
Help us keep the lights on

Dependencies

Used By

Total: 0