Reputation: 510
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
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
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