UIcollectionView with array no loading sections

im struggle with my cell model it's only showing my array position 0 in all cells
what i'm trying to reach is show in each UICollectionView the information inside
arregloBidimencional
which contains let episodes: [episodess]? and let tack: Int?
episodess is my main struct for the didSet inside each UICollectionviewCell
and tack is my identifier for each array of [episodess]

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        
    if collectionView == UI.castCollectionView{
            let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "identifierSeasons", for: indexPath) as! SeasonCell

        cell.backgroundColor = .clear
        let arreglo = arraySeasonsEpisodes[indexPath.item]
        cell.model = arreglo

        return cell
    }

var arraySeasonsEpisodes: [episodess] = [] its type of episodess

so my model to get the previous data is

struct episodess: Initiable {
    let episode_number: Int?
    let name: String?
    let still_path: String?
    init() {
            self.episode_number = 0
            self.name = ""
            self.still_path = ""       
        }   
    init(dictionary: NSDictionary) {
        self.episode_number = dictionary["episode_number"] as? Int ?? 0
        self.name = dictionary["name"] as? String ?? ""
        self.still_path = dictionary["still_path"] as? String ?? ""      
    }
    
}
struct arregloBidimencional: Initiable {
    let episodes: [episodess]?
    let tack: Int?   
    init() {       
        self.episodes = [episodess]()
        self.tack = 0     
        }  
    init(arreglo: [episodess], tag: Int) {
        self.episodes = arreglo
        self.tack = tag
    }
}

so the didset in UICollectionViewCell it's set like this

class SeasonCell: UICollectionViewCell {
    
    var model: episodess? {
        didSet {
            guard let viewModel = model else { return }

            let episodio = viewModel.episode_number
            let nombre = viewModel.name
            let guardado = viewModel.still_path
            episodeNumber.text = "Episode Number: \(episodio ?? 0)"
            episodeName.text = "Episode Name: \(nombre ?? "")"

            let image = "https://image.tmdb.org/t/p/w500\(guardado ?? "")"
            if image == "" || image == "undefined" {
                seasonImage.image = UIImage(named: "")
                seasonImage.contentMode = .scaleAspectFill
            }else{
                seasonImage.downloaded(from: image)
                seasonImage.contentMode = .scaleAspectFill
            }
        }
    }

this is how i storage the data from the json dictionary

let toneCategories = jsonDictionary["episodes"] as? [NSDictionary] ?? []
                    

                    
                       for category in toneCategories {
                        let show = episodess(dictionary: category)
                        arraySeasonsEpisodes.append(show)
                      
                        let number = Int(season_number) ?? 0
                        let reversedCollection = (1 ... number)
                        //for index in reversedCollection {
                        for (index, element) in reversedCollection.enumerated() {
                            print(index, ":", element)
                            let fixed = index - 1
                            if fixed <= 0 {
                                let arreglo = arregloBidimencional(arreglo: [show], tag: 0)
                                arregloDeArreglos.append([arreglo])
                            }else if fixed >= 1{
                                let fixed2 = index
                                let arreglo = arregloBidimencional(arreglo: [show], tag: fixed2)
                                arregloDeArreglos.append([arreglo])
                            }
                            
                        }
                        
                       }

print of arraySeasonsEpisodes

[MovieDataBase.episodess(episode_number: Optional(1), name: Optional("121045"), still_path: Optional("/b9hFk5kwRcFUorxLQsOHasJnbDH.jpg")), MovieDataBase.episodess(episode_number: Optional(2), name: Optional("131045"), still_path: Optional("/mSZDdQLHnDousFg35ndlmv42908.jpg")), MovieDataBase.episodess(episode_number: Optional(3), name: Optional("181045"), still_path: Optional("/57bidANnv5zdPmJckmPL9f4Ogb7.jpg")), MovieDataBase.episodess(episode_number: Optional(4), name: Optional("291045"), still_path: Optional("/swmIOzEJ8uIjCdd5B4w9Ln5qXsJ.jpg")), MovieDataBase.episodess(episode_number: Optional(5), name: Optional("301045"), still_path: Optional("/2x9v9YupwZnMBnvCUOwaOv8UEQV.jpg")), MovieDataBase.episodess(episode_number: Optional(6), name: Optional("311045"), still_path: Optional("/uFY25TSNrOxbL18jDV1pSjWPKEK.jpg")), MovieDataBase.episodess(episode_number: Optional(7), name: Optional("011145"), still_path: Optional("/8LGArTKq5oMnKR9AjdRd3ocxJWu.jpg")), MovieDataBase.episodess(episode_number: Optional(8), name: Optional("021145"), still_path: Optional("/yEBAannVEt2QhyUKyjlXhXrEVld.jpg")), MovieDataBase.episodess(episode_number: Optional(9), name: Optional("031145"), still_path: Optional("/nf1zvR7D4kN1Xa1wlxXeuUrWpOo.jpg")), MovieDataBase.episodess(episode_number: Optional(10), name: Optional("130146"), still_path: Optional("/1lTlSWY4chqpv1ibeQz4eYHaePf.jpg")), MovieDataBase.episodess(episode_number: Optional(11), name: Optional("140146"), still_path: Optional("/qTKxjZTbiCqZ6lywwfmfTLX8QnK.jpg")), MovieDataBase.episodess(episode_number: Optional(12), name: Optional("150146"), still_path: Optional("/8duv3ltJa7Olb721zsqcbss0kVx.jpg")), MovieDataBase.episodess(episode_number: Optional(1), name: Optional("Episode 1"), still_path: Optional("/24VlK7Ed5VFa0yE2kEmDPzyYks.jpg")), MovieDataBase.episodess(episode_number: Optional(2), name: Optional("Episode 2"), still_path: Optional("/eoyTsCYEAymTAhBgXIbIfW2jrwz.jpg")), MovieDataBase.episodess(episode_number: Optional(3), name: Optional("Episode 3"), still_path: Optional("/1EgiONNX9CgO6i4DjyeVBvsvT9v.jpg")), MovieDataBase.episodess(episode_number: Optional(4), name: Optional("Episode 4"), still_path: Optional("/4lZnqwPkNmnVEZ6ipID92BiWDkd.jpg")), MovieDataBase.episodess(episode_number: Optional(5), name: Optional("Episode 5"), still_path: Optional("/4wkH3s9d7YFvnjvQ24rS1pj4oUk.jpg")), MovieDataBase.episodess(episode_number: Optional(6), name: Optional("Episode 6"), still_path: Optional("/46XRAOhySNHl1O0qTHMUdUxfDcA.jpg")), MovieDataBase.episodess(episode_number: Optional(7), name: Optional("Episode 7"), still_path: Optional("/lbVYNXOtQSVU69ee7qbHWJ1f7b8.jpg")), MovieDataBase.episodess(episode_number: Optional(8), name: Optional("Episode 8"), still_path: Optional("/95UudD6foD0V7xJc345sJSZ9vUW.jpg")), MovieDataBase.episodess(episode_number: Optional(9), name: Optional("Episode 9"), still_path: Optional("")), MovieDataBase.episodess(episode_number: Optional(10), name: Optional("Episode 10"), still_path: Optional("")), MovieDataBase.episodess(episode_number: Optional(11), name: Optional("Episode 11"), still_path: Optional(""))]

enter image description here

Terms of Service

Privacy Policy

Cookie Policy