Gabriel Rodrigues
Gabriel Rodrigues

Reputation: 510

How do I load images from url to show in UITableView?

I'm loading json data from webservice using Alamofire, one of my request return a json like this:

"lorem ipsum...",
"http://site.ed/image.jpg"

Then I create a var texto: [String] = [] to receive all texts.

Now I need to adapt to receive image to show in UITableView

What I already do:

func loadPosts() {
    let url = "http://site.ed"
    Alamofire.request(.GET, url)
        .responseJSON { response in

            if let value: AnyObject = response.result.value {
                let post = JSON(value)
                for (_, subJson) in post {
                    if(self.verifyUrl(subJson.stringValue)){
                        print("Valide URL \(subJson.stringValue)")
                    }
                    self.texto.append(subJson.stringValue)
                }
            }
    }
}

func verifyUrl (urlString: String?) -> Bool {
    if let urlString = urlString {
        if let url  = NSURL(string: urlString) {
            return UIApplication.sharedApplication().canOpenURL(url)
        }
    }
    return false
}

In this print("Valide URL") i need to get the real image and put into a table, how can i do that ?

Upvotes: 0

Views: 153

Answers (1)

JZAU
JZAU

Reputation: 3567

Why not try some image library like KingFisher

What you need to do is just set imageView with url

imageView.kf_setImageWithURL(NSURL(string: "http://your_image_url.png")!)

Upvotes: 1

Related Questions