I'm trying to pass the data and got this error: 'subscript(_:)' is unavailable: cannot subscript String with an Int, use a String.Index instead.
Here is my code:
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell: CustomLoopsCell = beatTableView.dequeueReusableCell(withIdentifier: "firstLoopCell", for: indexPath) as! CustomLoopsCell
let beatLoop = overtunePacks[indexPath.row]
// On the lines which is down I'm getting this error
let beatDesc = loopsDesc[indexPath.row]
let beatProd = loopsProd[indexPath.row]
let beatAudio = loopsAudio[indexPath.row]
let beatInst = loopsInst[indexPath.row]
cell.loopNameLabel.text = beatDesc
cell.producerLabel.text = beatProd
cell.instrumentLabel.text = beatInst
Here is the code from another view controller, from where I'm passing the data:
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let vc = storyboard?.instantiateViewController(identifier: "BeatViewID") as? BeatPackViewController
vc?.beatInfoCollectName = beatInfoCollect[indexPath.row].name
vc?.beatProducerName = beatInfoCollect[indexPath.row].producer
vc?.imageBeat = beatInfoCollect[indexPath.row].imagename
vc?.loopsAudio = beatAudioCollect[indexPath.row].loopPath
vc?.loopsDesc = beatAudioCollect[indexPath.row].name
vc?.loopsInst = beatAudioCollect[indexPath.row].instrument
vc?.loopsProd = beatAudioCollect[indexPath.row].producer
self.navigationController?.pushViewController(vc!, animated: true)
}
Here is my variables in second view controller, where I'm passing data:
var loopsAudio = ""
var loopsDesc = ""
var loopsInst = ""
var loopsProd = ""
Here is what I want to display:
struct BeatLoops: Decodable {
let name: String
let instrument: String
let loopPath: String
let producer: String
var songURL : URL {
let components = loopPath.components(separatedBy: ".")
guard components.count == 2,
let url = Bundle.main.url(forResource: components[0], withExtension: components[1]) else { fatalError("Audio file is missing") }
return url
}
}
I'm parsing this data and have instance: var beatAudioCollect = [BeatLoops]()