Skip to content
Brian Mullen edited this page Dec 4, 2016 · 5 revisions

Built-in Supported Types

Bool,
String, Character,
Float, Double,
Int, Int8, Int16, Int32, Int64,
UInt, UInt8, UInt16, UInt32, UInt64,
Array, Dictionary,
URL, Date

Examples

let bool: Bool = try json.value(for: "bool")  
//bool == true

let string: String = try json.value(for: "string")  
//string == "Hello, Outlaw!"

let character: Character = try json.value(for: "character")  
//character == "O"

let float: Float = try json.value(for: "float")  
//float == 3.14

let double: Double = try json.value(for: "double")  
//double == 3.14159265359

let int: Int = try json.value(for: "int")  
//int == -3

let int8: Int8 = try json.value(for: "int8")  
//int8 == -8

let int16: Int16 = try json.value(for: "int16")  
//int16 == -16

let int32: Int32 = try json.value(for: "int32")  
//int32 == -32

let int64: Int64 = try json.value(for: "int64")  
//int64 == -64

let uint: UInt = try json.value(for: "uint")  
//uint == 3

let uint8: UInt8 = try json.value(for: "uint8")  
//uint8 == 8

let uint16: UInt16 = try json.value(for: "uint16")  
//uint16 == 16

let uint32: UInt32 = try json.value(for: "uint32")  
//uint32 == 32

let uint64: UInt64 = try json.value(for: "uint64")  
//uint64 == 64

let array: [String] = try json.value(for: "array")  
//array == ["Hello, Outlaw!", "Hello, Outlaw!"]

let dictionary: [String: String] = try json.value(for: "dictionary")  
//dictionary == ["message": "Hello, Outlaw!"]

let url: URL = try json.value(for: "url")  
//url.absoluteString == "http://molbie.co/"

let date: Date = try json.value(for: "date")
//ISO8601DateFormatter().string(from: date) == "2016-11-18T04:26:59Z"

Example JSON

{
	"bool": true,
    "string": "Hello, Outlaw!",
    "character": "O",
    "float": 3.14,
    "double": 3.14159265359,
    "int": -3,
    "int8": -8,
    "int16": -16,
    "int32": -32,
    "int64": -64,
    "uint": 3,
    "uint8": 8,
    "uint16": 16,
    "uint32": 32,
    "uint64": 64,
    "array": ["Hello, Outlaw!", "Hello, Outlaw!"],
    "dictionary": {"message": "Hello, Outlaw!"},
    "url": "http://molbie.co/",
    "date": "2016-11-18T04:26:59Z",
}

Clone this wiki locally