title: grab data from api for UICollectionView inside UICollectionViewCell using alamofire and swiftyJson
body: <p>hello I am working on an application for retrieving data about movies but I have a problem , I am using a CollectionView for displaying movie categories and inside these categories (inside the Collection View Cells) I am using another collection View to display movies according to the movie category but I can't populate the cells of the second collection view because it is a subclass of custom cell and I have also created a xib file for the custom cell and I am trying to implement delegate and datasource methods for the second collection view inside the class that I have made for the custom cell this is a part of my code :</p>
  
  <pre><code>func parseJson(category:MovieCategory)
     {
  
  
         let currentCategory = category
         let parameters = ["api_key":"8460d476d21be7e26a99234d8ca8de51","sort_by":"false","include_video":"false","with_genres":currentCategory.genreID]
  
         Alamofire.request(AppModel().url, method: .get, parameters: parameters).responseJSON { (response) in
  
             if response.result.isSuccess{
                 let movieJSON = JSON(response.result.value!)
  
                 for i in 0..&lt;20{
  
                     let title = movieJSON["results"][i]["title"].stringValue
                     let posterPath = movieJSON["results"][i]["poster_path"].stringValue
                     let overview = movieJSON["results"][i]["overview"].stringValue
                     let dateReleased = movieJSON["results"][i]["release_date"].stringValue
                     let voteAverage = movieJSON["results"][i]["vote_average"].stringValue
                   print(title)
                     if let safeImage = AppModel().createImage(posterPath: posterPath)
                     {
                         let movieDetails = MovieDetails(movieTitle: title, poster: safeImage, voteAverage: voteAverage, overview: overview, releaseDate: dateReleased)
  
                         currentCategory.categoryMovies.append(movieDetails)
  
  
  
  
                     }
  
                 }
  
             }
  
         }
     }
  </code></pre>
  
  <p>and the where I want to use the retrieved data from the api:</p>
  
  <pre><code>class CategoryCollectionViewCell:UICollectionViewCell,UICollectionViewDelegate,UICollectionViewDataSource{
  
  @IBOutlet weak var sectionName: UILabel!
  
  @IBOutlet weak var movieCollectionView: UICollectionView!
  
  var sectionNumber:Int = 0
  
  let appModel = AppModel()
  
  override func awakeFromNib() {
      super.awakeFromNib()
      movieCollectionView.delegate = self
      movieCollectionView.dataSource = self
  
      movieCollectionView.register(UINib(nibName: "CollectionViewCell", bundle: nil), forCellWithReuseIdentifier: "cell")
  
  
  
  }
  
  
  
  @IBAction func viewAllPressed(_ sender: UIButton) {
  }
  func numberOfSections(in collectionView: UICollectionView) -&gt; Int {
      appModel.movieCategories.count
  }
  func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -&gt; Int {
      return appModel.movieCategories[section].categoryMovies.count
  }
  
  func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -&gt; UICollectionViewCell {
      let cell = movieCollectionView.dequeueReusableCell(withReuseIdentifier: "categoryCell", for: indexPath) as! CollectionViewCell
      cell.posterImage.image = appModel.movieCategories[indexPath.section].categoryMovies[indexPath.item].poster
      return cell
  
  }
  </code></pre>
  
  <p>}
  these are the model classes:</p>
  
  <pre><code>class MovieDetails{
  let movieTitle:String
  let poster:UIImage
  let voteAverage:String
  let overview:String
  let releaseDate:String
  init(movieTitle:String,poster:UIImage,voteAverage:String,overview:String,releaseDate:String) {
      self.movieTitle = movieTitle
      self.overview = overview
      self.poster = poster
      self.releaseDate = releaseDate
      self.voteAverage = voteAverage
  }
  </code></pre>
  
  <p>}</p>
  
  <pre><code>class MovieCategory {
  var genreID:String = ""
  var categoryTitle:String = ""
  var categoryMovies:[MovieDetails] = []
  init(genreID:String,categoryTitle:String) {
      self.genreID = genreID
      self.categoryTitle = categoryTitle
  }
  </code></pre>
  
  <p>}</p>
  
  <p>I think my problem is that I don't know where to call parseJson in side CategoryCollectionViewCell and where to call reloadData().
  if you know any thing about that please help me 
  thankYou.</p>