title: iOS multiple JSON file data transfer through segue in Swift
body: <p>I am trying to make a country weather forecast app, I have vc1 and vc2.</p>
  <p>The JSON file to be parsed in vc2 exists for each country, and when the table view cell of vc1 is clicked, we try to implement parsing the JSON file of the country in vc2.</p>
  <p>However, I do not know how to pass the JSON file name from vc1 to vc2 through segue.</p>
  <p>When passing from vc1 to vc2 using segue, the variable is nil. Is there any solution?</p>
  <p>Thanks for reading.</p>
  <p>vc1</p>
  <pre class="lang-swift prettyprint-override"><code>class MainViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
      
      @IBOutlet weak var tableView: UITableView!
      var countries = [Countries]()
      
      override func viewDidLoad() {
          super.viewDidLoad()
          tableView.delegate = self
          tableView.dataSource = self
          
          let jsonDecoder = JSONDecoder()
          guard let dataAsset = NSDataAsset(name: &quot;countries&quot;)
              else {
                  return
          }
          do {
              countries = try jsonDecoder.decode([Countries].self, from: dataAsset.data)
          } catch {
              print(error.localizedDescription)
          }
          tableView.reloadData()
      }
      
      
      func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -&gt; Int {
          return countries.count
      }
      
      func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -&gt; UITableViewCell {
          let cell = tableView.dequeueReusableCell(withIdentifier: &quot;MainCell&quot;, for: indexPath)
          let country: Countries = countries[indexPath.row]
          cell.imageView?.image = UIImage(named: &quot;flag_&quot; + country.asset_name)
          cell.textLabel?.text = country.korean_name
          return cell
      }
      
      // Data Transfer
      override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
          guard let nextViewController: SecondViewController = segue.destination as? SecondViewController else {
              return
          }
          guard let cell: UITableViewCell = sender as? UITableViewCell else {
              return
          }
          func name(indexPath: IndexPath) {
              let country: Countries = countries[indexPath.row]
              nextViewController.title = cell.textLabel?.text
              nextViewController.secondAssetName = country.asset_name
          }
          
      }
  }
  </code></pre>
  <p>vc2</p>
  <pre class="lang-swift prettyprint-override"><code>class SecondViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
      
      
      var weathers = [Weather]()
      var secondAssetName: String?
          
      @IBOutlet weak var tableView: UITableView!
      
          override func viewDidLoad() {
          super.viewDidLoad()
              
              self.tableView.delegate = self
              self.tableView.dataSource = self
          
              
          let jsonDecoder = JSONDecoder()
              guard let dataAsset = NSDataAsset(name: secondAssetName ?? &quot; &quot;) else {
              return
          }
          do {
              weathers = try jsonDecoder.decode([Weather].self, from: dataAsset.data)
          } catch {
              print(error.localizedDescription)
          }
          tableView.reloadData()
      }
      
      
      func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -&gt; Int {
          return weathers.count
      }
  
      func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -&gt; UITableViewCell {
          let cell: CustomTableViewCell = tableView.dequeueReusableCell(withIdentifier: &quot;CustomCell&quot;, for: indexPath) as! CustomTableViewCell
          let weather: Weather = weathers[indexPath.row]
          
          switch weather.state {
              case 10:
                  cell.cellImageView?.image = UIImage(named: &quot;sunny.png&quot;)
              case 11:
                  cell.cellImageView?.image = UIImage(named: &quot;cloudy.png&quot;)
              case 12:
                  cell.cellImageView?.image = UIImage(named: &quot;rainy.png&quot;)
              case 13:
                  cell.cellImageView?.image = UIImage(named: &quot;snowy.png&quot;)
              default:
                  return cell
          }
          cell.cityNameLabel.text = weather.city_name
          cell.temperatureLabel.text = String(weather.celsius)
          cell.rainfallProbabilityLabel.text = String(weather.rainfall_probability)
          return cell
      }
  }
  </code></pre>
  <p><a href="https://i.stack.imgur.com/3DjEs.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/3DjEs.jpg" alt="enter image description here" /></a></p>