Как решить эту ошибку Необязательно (Alamofire.AFError.invalidURL)? - PullRequest
0 голосов
/ 08 февраля 2019

Когда я связываю свое приложение с URL, появляется эта ошибка

Необязательно (Alamofire.AFError.invalidURL)

import UIKit
import Alamofire
import SwiftyJSON

class MainViewController: UIViewController , UITableViewDataSource , UITableViewDelegate {

  @IBOutlet weak var tableView: UITableView?

  var foods :[[String: Any]] = [[String: Any]]()

  // let foodsUrl : String = "​​https://api.myjson.com/bins/1bnsyj"

  override func viewDidLoad() {
    super.viewDidLoad()


    Alamofire.request("​​https://api.myjson.com/bins/1bnsyj",method : .get).responseJSON { (response) in
      if let responseValue = response.result.value as! [String: Any]? {
        if let responseFoods = responseValue["items"] as! [[String: Any]]? {

          self.foods = responseFoods
          self.tableView?.reloadData()

        }
      }
      else {
        print("error : \(String(describing: response.result.error))")
      }
    }
  }

  //Mark - UITableViewDataSource & UITableViewDelegate

  func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return 14
  }

  func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: "FoodTableViewCell") as! FoodTableViewCell

    if self.foods.count > 0 {
      let  eachFood = foods[indexPath.row]
      cell.lblFoodName?.text = (eachFood["name"] as? String) ?? ""
      cell.lblFoodDescription?.text = (eachFood["description"] as? String) ?? ""
    }

    return cell
  }
}
...