<repo_name>vishalmodem/ExampleProject<file_sep>/ExampleProject/Controllers/ViewController.swift
//
//  ViewController.swift
//  ExampleProject
//
//  Created by <NAME> on 6/19/18.
//  Copyright © 2018 <NAME>. All rights reserved.
//

import UIKit
import CoreData
import RequestManagerFramework
import CustomButtonFramework

class ViewController: UIViewController {

var actors : [Actor] = [Actor]()
    var hollyActors = [HollyActors]()
    let context = (UIApplication.shared.delegate as! AppDelegate).persistentContainer.viewContext
    override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)
        loadData()
    }
    @IBAction func Make(_ sender: UIButton) {
        RequestManager.shared.getActorsData({ (actors) in
            self.actors = actors
            if self.hollyActors.count < 6 {
                self.hollyActors.forEach({ (hA) in
                    self.context.delete(hA)
                    self.saveData()
                })
                self.loadData()
            let operationQueue = OperationQueue()
                operationQueue.maxConcurrentOperationCount = 1
            for actor in actors{
                let operation = {
                let hA = HollyActors(context: self.context)
                hA.image = actor.image
                hA.name = actor.name
                self.hollyActors.append(hA)
                self.saveData()
                }
                operationQueue.addOperation(operation)
            }
            }
            })
                DispatchQueue.main.async {
                    self.performSegue(withIdentifier: "segue", sender: self)
                }
    }
    
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        if segue.identifier == "segue" {
            if let destinationVC = segue.destination as? ActorsTVC {
                guard let s = sender as? ViewController else{ return }
                destinationVC.actors = s.actors
            }
        }
    }
    @IBAction func unwindSegue(_ sender: UIStoryboardSegue){
}
    
    private func saveData(){
        do{
        try context.save()
        } catch{
            print(error)
        }
    }
    private func loadData(){
        let request: NSFetchRequest = HollyActors.fetchRequest()
        do{
            hollyActors = try context.fetch(request)
            print(hollyActors.count)
        }
        catch{
            print(error)
        }
    }

}
<file_sep>/ExampleProject/Controllers/ImageShowVC.swift
//
//  ImageShowVC.swift
//  ExampleProject
//
//  Created by <NAME> on 6/20/18.
//  Copyright © 2018 <NAME>. All rights reserved.
//

import UIKit
import CustomButtonFramework

class ImageShowVC: UIViewController {

    @IBOutlet weak var NameLbl: UILabel!
    @IBOutlet weak var imageView: UIImageView!
    var image :UIImage?
    var name : String?{
        didSet{
            navigationItem.title = name
        }
    }
    override func viewDidLoad() {
        super.viewDidLoad()

        guard let img = image else { return }
        imageView.image = img
        NameLbl.text = name
    }

    @IBAction func dismissClicked(_ sender: UIButton) {
        
    }
    
}
<file_sep>/ExampleProject/Controllers/ActorTableViewCell.swift
//
//  ActorTableViewCell.swift
//  ExampleProject
//
//  Created by <NAME> on 6/21/18.
//  Copyright © 2018 <NAME>. All rights reserved.
//

import UIKit
import RequestManagerFramework

class ActorTableViewCell: UITableViewCell {

    @IBOutlet weak var imageViewer: UIImageView!
    @IBOutlet weak var nameLbl: UILabel!
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }
    func updateCell(actor:Actor){
        nameLbl.text = actor.name
        let url = URL(string: actor.image!)
        if let imageUrl = url {
            do {
                let data = try Data(contentsOf: imageUrl)
                self.imageViewer.image = UIImage(data: data)
            } catch{
                print(error.localizedDescription)
            }
    }
  
    }
}
<file_sep>/ExampleProject/Controllers/ActorsTVC.swift
//
//  ActorsTVC.swift
//  ExampleProject
//
//  Created by <NAME> on 6/20/18.
//  Copyright © 2018 <NAME>. All rights reserved.
//

import UIKit
import CoreData
import RequestManagerFramework

class ActorsTVC: UITableViewController {

    var actors : [Actor]?
    var hollyActors = [HollyActors]()
    let context = (UIApplication.shared.delegate as! AppDelegate).persistentContainer.viewContext
    override func viewDidLoad() {
        super.viewDidLoad()
        tableView.estimatedRowHeight = tableView.rowHeight
        tableView.rowHeight = UITableViewAutomaticDimension
        loadData()
        
    }

    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return actors?.count ?? 0
    }

    
    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! ActorTableViewCell
        cell.updateCell(actor: actors![indexPath.row])
        return cell
    }
    
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        if segue.identifier == "segue1" {
            if let destinationVC = segue.destination as? ImageShowVC {
                //guard let actors = self.actors else{ return}
                guard let cell = sender as? UITableViewCell  else { return }
                guard let indexpath = tableView.indexPath(for: cell), let imgURL = hollyActors[indexpath.row].image, let name = hollyActors[indexpath.row].name else { return }
                do{
                    guard let url = URL(string: imgURL) else{ return}
                    let data = try Data(contentsOf: url)
                    let image = UIImage(data: data)
                    destinationVC.image = image
                    destinationVC.name = name

                } catch {
                    print(error.localizedDescription)
                }
            }
        }
    }
 

   
    override func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
        return true
    }


  
    override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
        if editingStyle == .delete {
            // Delete the row from the data source
            actors?.remove(at: indexPath.row)
            context.delete(hollyActors[indexPath.row])
            do{
                try context.save()
            } catch{
                print(error)
            }
            tableView.deleteRows(at: [indexPath], with: .fade)
loadData()
        }
    }
    private func loadData(){
        let request: NSFetchRequest = HollyActors.fetchRequest()
        do{
            hollyActors = try context.fetch(request)
        }
        catch{
            print(error)
        }
    }

}
