I don't get when I call the let item = stationData[0] it says that its index is out of range... But inside my Alamofire request it returns that it has data...
Below is my code.
my alamofire is inside the viewdid load.
Alamofire.request(url, method: .post, parameters: parameters, encoding: JSONEncoding.default).responseJSON {
responseData in
if responseData.result.value != nil {
let swiftyJson = JSON(responseData.result.value as Any)
if let data = swiftyJson["data"].arrayObject as? [[String: Any]] {
if data.isEmpty{
print("NO DATA FOUND")
}
else {
self.stationData = data.map(StationData.init)
}
}
}
}
Here is my code where I use stationData
extension ParameterViewController: UICollectionViewDataSource {
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
switch itemType {
case .items:
return parameterName1.count
case .items1:
return parameterName2.count
case .items2:
return parameterName3.count
default:
print("No count to get")
}
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "ValuesViewCell", for: indexPath) as! ValuesViewCell
let item = stationData[0]
switch itemType {
case .items:
cell.setData(parameterName: self.parameterName1[indexPath.row], parameterValue: item.vakue1)
case .items1:
cell.setData(parameterName: self.parameterName2[indexPath.row], parameterValue: item.value2)
case .items2:
cell.setData(parameterName: self.parameterName3[indexPath.row], parameterValue: item.value3)
default:
print("No cell to insert")
}
return cell
}
}