I'm using Alamofire to fetch data from server and then put them in an array of CarType
objects which CarType
is my struct. what I get from server is name
, id
and iconUrl
. from iconUrls i want to download icons and put them in icon
. after that I'll use icon
and name
in a collection view. my Alamofire request is:
var info = [CarType]()
Alamofire.request(.GET,"url")
.responseJSON { response in
for (_,subJson):(String, JSON) in json["result"]
{
let name = subJson["name"].string
let iconUrl = subJson["icon"].string
let id = subJson["id"].int
info.append(CarType(id: id!, name: name!, iconUrl: iconUrl! , image: UIImage()))
}
my struct is:
import Foundation
import UIKit
struct CarType {
var name : String
var id : Int
var iconUrl : String
var icon : UIImage
}
I want to download images before using them in collectionView. How can i download images (using AlamofireImage) and put them in related carType icon property?