Demo JSON:
{ "array": [ { "birthday": 2015-12-24, "name": "sheepy" }, { "birthday": 2015-12-24, "name": "sleepy" } ], "boolean": true, "number": 123, "string": "Hello World" }
class JSONModel: NSObject {
var array = []
var boolean = false
var number = 0
var string = ""
}
class PersonModel: NSObject {
var birthday = NSDate()
var name = ""
}
getDataFromUrl(Constant.DemoAPI, method: .GET, parameter: nil) { data, error in
if let jsonData = data {
let jsonModel = jsonData => JSONModel.self
}
if let httpError = error {
print(httpError)
}
}
if let model = jsonModel {
let person = model.array[0] => PersonModel.self
}
let data = person => NSData.self
let dict = person.convertToDictinary()