我想将几个图像加载到模型中。我正在尝试使用 loadImage() 函数和 inout 参数来解决这个问题。但由于某种原因,图像变量总是空的。我没有看到图像。
这里有什么问题?
public var image: UIImage = UIImage()
// Somewhere in the init function
self.loadImage("http://www.domain.com/cats.img", targetImage: &self.image)
func loadImage(url:String, inout targetImage:UIImage) {
dispatch_group_enter(self.dispatch_group);
println("Start loading image \(url)")
var request:Alamofire.Request = Alamofire.request(.GET, url).responseImage() {
(request, _, image, error) in
if error == nil && image != nil {
println("imageRequestSuccess")
// Save the image to the model property
targetImage = image!
// Dispatch if success
dispatch_group_leave(self.dispatch_group)
} else {
println("imageRequestFailure")
// Dispatch also to handle failure
dispatch_group_leave(self.dispatch_group)
}
}
}