Я не могу правильно передать данные из коллекции ViewController в ViewController. На вк показывает тот же товар. Я не понимаю, где мои ошибки
struct Goods {
var goods = [String]()
}
var namesOfGoods = [Goods(goods: ["Good1", "Good2", "Good3"]),
Goodsl(goods: ["Good4", "Good5", "Good6"]),
Goods(goods: ["Good7"])]
class ProductsCollectionViewController: UIViewController, UICollectionViewDelegate, UICollectionViewDataSource {
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "show" {
var productDetailVC = segue.destination as! DescriptionProductViewController
let cell = sender as! UICollectionViewCell
let indexPath = collectionView.indexPath(for: cell)
let product = Goods[(indexPath?.row)!]
productDetailVC.name = product
}
}
class DescriptionProductViewController: UIViewController {
var name: Goods!
@IBOutlet weak var productIamge: UIImageView!
@IBOutlet weak var priceLabel: UILabel!
@IBOutlet weak var nameLabel: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
nameLabel.text = name.joined(separator: "")
}