Reputation: 113
There are total number of 114 data to fetch from web through API request. But it takes 10-15 seconds to load the data. I tried DispatchQueue() but found no improvement. ViewDidLoad and JSON parse code:
func parseJSON() {
let url = URL(string: "https://api.alquran.cloud/v1/quran/ar.alafasy")
guard url != nil else{
print("URL Founr Nill")
return
}
URLSession.shared.dataTask(with: url!) { (data, response, error) in
if error == nil && data != nil{
do{
let response = try JSONDecoder().decode(Surah.self, from: data!)
self.surahName = response.data.surahs
DispatchQueue.main.async {
self.tableView.reloadData()
self.tableView.tableFooterView = UIView(frame: .zero)
}
}catch{
print(error)
}
}
}.resume()
}
Table View code:
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell:QuranAudioCell = tableView.dequeueReusableCell(withIdentifier: "cell") as! QuranAudioCell
let surah = surahName[indexPath.row]
cell.nameLbl.text = surah.englishName
cell.arabicNameLbl.text = surah.name
return cell
}
Upvotes: 0
Views: 541
Reputation: 50089
Based on the code above the only thing that can be sooo slow is the networr request you are making.
Your DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 0) {
in viewDidLoad is rather pointless TBH
The only way to speed this up at this point is debugging the network call.
Upvotes: 1