1- Replace this
let jsonObject = try JSONSerialization.jsonObject(with: data as Date, options: .allowFragments)
with
let jsonObject = try JSONSerialization.jsonObject(with: data as Data, options: .allowFragments)
it’s a Data
object not Date
2- no need for fragments it can be
let jsonObject = try JSONSerialization.jsonObject(with: data as Data, options: [])
if let object = jsonObject as? [NSString: Any]
3- this line
let data = NSData(contentsOf: url)
blocks main thread consider using URLSession
or Alamofire
solved Cannot convert value of type ‘NSData’ to type ‘Date’ in coercion in json work? [closed]