I get this error when I run the application.
Fatal error: Index out of range: file Swift/ContiguousArrayBuffer.swift, line 444
I pull data from firebase and upload it to MapKit in UITableViewCell. It was working on my friend's computer but when I run it again on my own computer, I got this error. How can I solve this problem?
ViewController:
import UIKit
import Firebase
import SDWebImage
import MapKit
import CoreLocation
class anasayfaViewController: UIViewController, UITableViewDelegate, UITableViewDataSource,CLLocationManagerDelegate, MKMapViewDelegate {
@IBOutlet weak var tableView: UITableView!
var UserNameArray = [String]()
var UserCommentArray = [String]()
var UserImageArray = [String]()
var DocumentIDarray = [String]()
var UserLocationArray = [GeoPoint]()
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return UserNameArray.count
}
/*
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return UITableView.automaticDimension
}
*/
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as! HomeCell
let username = UserNameArray[indexPath.row]
let comment = UserCommentArray[indexPath.row]
let imageURL = UserImageArray[indexPath.row]
let location = UserLocationArray[indexPath.row]. ------ (Error Line )
cell.prepare(username: username, imageURL: imageURL, comment: comment, location: location)
return cell
}
override func viewDidLoad() {
super.viewDidLoad()
tableView.delegate = self
tableView.dataSource = self
//tableView.estimatedRowHeight = 100
getdataFromFirestore()
}
func getdataFromFirestore(){
let firestoreDatabase = Firestore.firestore()
firestoreDatabase.collection("Posts").order(by: "Date", descending: true).addSnapshotListener { [weak self] (snapshot, error) in
if let error = error {
print(error.localizedDescription)
return
}
if snapshot?.isEmpty != true {
self?.UserCommentArray.removeAll(keepingCapacity: false)
self?.UserNameArray.removeAll(keepingCapacity: false)
self?.UserImageArray.removeAll(keepingCapacity: false)
self?.documentIDarray.removeAll(keepingCapacity: false)
self?.UserLocationArray.removeAll(keepingCapacity: false)
for document in snapshot!.documents {
let documentID = document.documentID
self?.documentIDarray.append(documentID)
if let sharedBy = document.get("SharedBy") as? String {
self?.UserNameArray.append(sharedBy)
}
if let sharedComment = document.get("SharedComment") as? String {
self?.UserCommentArray.append(sharedComment)
}
if let sharedUrl = document.get("imageUrl") as? String {
self?.UserImageArray.append(sharedUrl)
}
if let sharedLocation = document.get("Location") as? GeoPoint {
self?.UserLocationArray.append(sharedLocation)
}
}
self?.tableView.reloadData()
}
}}
}