fatal error: Index out of range

In case your app crashes in

 let items = allSongsArray[indexPath.row]

as you check if the allSongsArray.count, u can safe guard it by making sure that the [indexPath.row] doesn't exceed your array count. so u can write a simple if condition as;

if allSongsArray.count > 0 && indexPath.row < allSongsArray.count {

  //Do the needful

}

You should return allSongsArray.count and to avoid being returned empty cells use yourTableView.reloadData after you fill your allSongsArray.


Please return the actual array count instead of static

return allsongsarray.count

When you first create the array it is empty. Hence, it will give you out of bound error.

Try to return the count of the songs array instead.

1st you need to get the data into the array and then update the table view.

Here is a sample code:

@IBAction private func refresh(sender: UIRefreshControl?) {
        if myArray.count > 0 {
              self.tableView.reloadData()
              sender?.endRefreshing()
        } else {
              sender?.endRefreshing()
        }
    }