func callApi(){
let sessionConfig = URLSessionConfiguration.default
let sessionUrl = URLSession(configuration: sessionConfig)
let url = URL(string: "URL")!
let request: URLRequest = URLRequest(url:url)
let task = sessionUrl.dataTask(with: request){
(data, response, error) in
if error != nil {
print(error!.localizedDescription)
} else{
do {
if let json = try! JSONSerialization.jsonObject(with: data!, options: .allowFragments) as? [Any] {
/*for item in json {
if let object = item as? [String: Any]{
print(object)
}
}*/
if let result = json as? NSArray {
for dict in result {
if let respDict = dict as? Dictionary<String, AnyObject>{
self.noteData.append(NoteData.init(responseDict: respDict))
}
}
}
// Reload data of TableView/CollectionView
DispatchQueue.main.async {
self.tblView.reloadData()
}
}
}catch {
print("error in JSONSerialization")
}
}}
task.resume()
}
Comments
Post a Comment