title: How to add multi arrays in one section of Collection View Cell which that collection view inside tableView cell?
body: <p>-Hello guys I have UIViewContoller consist of TableView and collectionView.
  The tableView has three Sections and third one contains  dynamic cell .The third cell contains collectionView also is dynamic.</p>
  
  <p>-The problem is with CollectionView ,</p>
  
  <p>I have 3 arrays each array contains names of images </p>
  
  <pre><code>    var dataSheet = ["1", "2", "3"] 
      var partList  = ["4", "5", "6"] 
      var drawing  = ["7", "8", "9"] 
  </code></pre>
  
  <p>I should show those arrays in one collectionViewCell , I don't want add them in one array because each array belongs to different row in the tableview, when I run app and open this page and I am trying to select the last index of the collectionView my app crash and tell me  indexPath is out of range.</p>
  
  <p>//TableView code </p>
  
  <pre><code>      func numberOfSections(in tableView: UITableView) -&gt; Int {
              return 4
          }
  
       func tableView(_ tableView: UITableView, numberOfRowsInSection   section: Int) -&gt; Int {
          switch section {
          case 0:
              return 1
          case 1 :
              return 1
          case 1 :
              return 1
          case 2 :
              return tabelviewSectionNumber.count
          default:
              return 0
          }
      }
  
   func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -&gt; UITableViewCell { 
          switch indexPath.section {
          case 0:
              let ComponentkksCell = tableView.dequeueReusableCell(withIdentifier: "componentKKS", for: indexPath) as! componentKKS_TVC
  
              ComponentkksCell.setUp(data: DescriptionArray[indexPath.row])
              return ComponentkksCell
  
  
          case 1 :
              let SystemDescriptionCell = tableView.dequeueReusableCell(withIdentifier: "SystemDescription_TVC", for: indexPath) as! SystemDescription_TVC
             SystemDescriptionCell.setUp(data: DescriptionArray[indexPath.row])
              return SystemDescriptionCell
  
          case 2:
              let DataSheetCell = tableView.dequeueReusableCell(withIdentifier: "DataSheet_TVC", for: indexPath) as! DataSheet_TVC
              DataSheetCell.setTableViewDelegateAndDataSource(dataSourceDelegate: self, forRow: indexPath.row)
              DataSheetCell.titlesections.text = tabelviewSectionNumber[indexPath.row]
             self.indexPath.append(indexPath.row)
  
              return DataSheetCell
  
  
  
          default:
              return UITableViewCell()
          }
  </code></pre>
  
  <p>// collectionView Code </p>
  
  <pre><code>func numberOfSections(in collectionView: UICollectionView) -&gt; Int {
          return 1
      }
  
      func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -&gt; Int {
          if shareVar.shared.mech == true {
              return getCurrentArray()?.count ?? 0
          } else if shareVar.shared.elec == true {
              return getCurrentArray()?.count ?? 0
          } else {
          return 0
          }
      }
  
      func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -&gt; UICollectionViewCell {
          let dataCell = collectionView.dequeueReusableCell(withReuseIdentifier: "dataImages", for: indexPath) as! SEH_DRA_COMCell
          if let currentImage = getCurrentArray()?[indexPath.row]{
              if shareVar.shared.mech == true {
                  dataCell.imageData.image = UIImage(named: currentImage )
  
              } else if shareVar.shared.elec == true {
                  dataCell.imageData.image = UIImage(named: currentImage )
              }
          }
  
          return dataCell
      }
  
  
      func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
          guard let currentImage = getCurrentArray()?[indexPath.item] else {return}
               print(indexPath.item)
            print(currentImage)
          presenter?.didSelectImage(image: currentImage)
      }
  </code></pre>
  
  <ul>
  <li><p>what I have done to add the 3 arrays in one collectionView cell
  1- I have created 2 ARRAYS </p>
  
  <p>var elecData: [Int: [String]] = [:]
      var mechData : [Int :  [String]] = [:] 
  2- and then I toke each array and add it to the those arrays I have created</p>
  
  <p>self.mechData[0] = dataSheet
   self.mechData[1] = partList
   self.mechData [2] = drawing
   self.elecData [0] = dataSheet
   self.elecData[1] = wiring</p></li>
  </ul>
  
  <p>3- this func to generate the current array </p>
  
  <pre><code>func getCurrentArray() -&gt; [String]? {
      var array = [String]()
      if shareVar.shared.mech == true {
          for index in indexPath {
              array = self.mechData[index] ?? [""]
          }
      } else if shareVar.shared.elec == true{
          for index in indexPath {
          array = self.elecData[index] ?? [""]
          }
      }
      return array
  }
  </code></pre>