Image Display Swift 4

Asked by At

I have a tableview cell, I need to display an image in that cell. First I will upload an image from iPhone(local device) to server. And I get a response in the form like this

        Alamofire.request(urls).responseJSON { (response) in
           if((response.result.value) != nil) {
             var jsonVar = JSON(response.result.value!)

            if let da = jsonVar.arrayObject
                self.data2 = da as! [[String : AnyObject]]


             func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell

                let iP = data2[indexPath.row]

                var mediaP = iP["mediaPath"] as? String

                if mediaP?.contains("img") ?? false {

                cell2.imageName.image = load(fileName: mediaP ?? "")

          This to get image from Result URL 

       func load(fileName: String) -> UIImage? {
       let fileURL = documentsUrl.appendingPathComponent(fileName)
       do {
        let imageData = try Data(contentsOf: fileURL)
        print("func load(fileName: String) ===========   \(imageData)")
        return UIImage(data: imageData)
    } catch {
        print("Error loading image : \(error)")
    return nil

The URL from JSON response is this file:///var/mobile/Containers/Data/Application/CE4E7A90-FAE4-46D4-B667-D09476888CD2/Documents/img_290420191206066330.png

How can I use this Response to display image in tableview cell.

0 Answers