Alamofire general request











up vote
-2
down vote

favorite












Could you help me please with this



I'm trying to pull data from API using Alamofire. Is it possible to pull simple data like ["title"] and Image in the same request and populate it in table view?



Here's my code:



Alamofire.request(baseURL).responseJSON { (response) in
switch response.result {
case .success:
if let value = response.result.value{
let json = JSON(value)
json.forEach({ (temp) in
let title = temp.1["title"].stringValue
let run = temp.1["run"].stringValue
let image = temp.1["thumb"].stringValue
let newmodel = Schedule(title: title, run: run, image: image)
self.scheduleArray.append(newmodel)
})

}
case .failure(let error):
print(error.localizedDescription)
}
DispatchQueue.main.async {
self.tableView.reloadData()
}
}
}









share|improve this question






















  • "Is it possible to pull simple data like" - Yes, anything a HTTP server can produce, you can consume - which raises the questions over, what is the server responding with? You seem to trying to parse some JSON, is the server returning a JSON response? You question is to general and doesn't point to a specific problem or issue. Were you using a previous approach (URLSession?) which was working and this isn't? What URL are you communicating with? What are the inputs and expected outputs? Are you having trouble parsing the result or populating the table?
    – MadProgrammer
    Nov 21 at 21:06










  • Oh no, I don't have problem with populating data. I just wanted to write 1 Alamofire request for simple objects and image data as well
    – Акарыс Турганбекулы
    Nov 21 at 21:08










  • So you have, two requests to make that return different data sets and you want to some how combine them?
    – MadProgrammer
    Nov 21 at 21:10










  • Yes, something like Alamofire.request(baseURL).response { (response, error, data) in
    – Акарыс Турганбекулы
    Nov 21 at 21:12










  • This might be beyond the scope of your intention, but I'd consider looking something like "PromiseKit" or "Hydra", which would manage the execution of two async operations and a much more elegant way, other then using a bunch of semaphores and other locking/notification mechanisms ... just saying
    – MadProgrammer
    Nov 21 at 21:14















up vote
-2
down vote

favorite












Could you help me please with this



I'm trying to pull data from API using Alamofire. Is it possible to pull simple data like ["title"] and Image in the same request and populate it in table view?



Here's my code:



Alamofire.request(baseURL).responseJSON { (response) in
switch response.result {
case .success:
if let value = response.result.value{
let json = JSON(value)
json.forEach({ (temp) in
let title = temp.1["title"].stringValue
let run = temp.1["run"].stringValue
let image = temp.1["thumb"].stringValue
let newmodel = Schedule(title: title, run: run, image: image)
self.scheduleArray.append(newmodel)
})

}
case .failure(let error):
print(error.localizedDescription)
}
DispatchQueue.main.async {
self.tableView.reloadData()
}
}
}









share|improve this question






















  • "Is it possible to pull simple data like" - Yes, anything a HTTP server can produce, you can consume - which raises the questions over, what is the server responding with? You seem to trying to parse some JSON, is the server returning a JSON response? You question is to general and doesn't point to a specific problem or issue. Were you using a previous approach (URLSession?) which was working and this isn't? What URL are you communicating with? What are the inputs and expected outputs? Are you having trouble parsing the result or populating the table?
    – MadProgrammer
    Nov 21 at 21:06










  • Oh no, I don't have problem with populating data. I just wanted to write 1 Alamofire request for simple objects and image data as well
    – Акарыс Турганбекулы
    Nov 21 at 21:08










  • So you have, two requests to make that return different data sets and you want to some how combine them?
    – MadProgrammer
    Nov 21 at 21:10










  • Yes, something like Alamofire.request(baseURL).response { (response, error, data) in
    – Акарыс Турганбекулы
    Nov 21 at 21:12










  • This might be beyond the scope of your intention, but I'd consider looking something like "PromiseKit" or "Hydra", which would manage the execution of two async operations and a much more elegant way, other then using a bunch of semaphores and other locking/notification mechanisms ... just saying
    – MadProgrammer
    Nov 21 at 21:14













up vote
-2
down vote

favorite









up vote
-2
down vote

favorite











Could you help me please with this



I'm trying to pull data from API using Alamofire. Is it possible to pull simple data like ["title"] and Image in the same request and populate it in table view?



Here's my code:



Alamofire.request(baseURL).responseJSON { (response) in
switch response.result {
case .success:
if let value = response.result.value{
let json = JSON(value)
json.forEach({ (temp) in
let title = temp.1["title"].stringValue
let run = temp.1["run"].stringValue
let image = temp.1["thumb"].stringValue
let newmodel = Schedule(title: title, run: run, image: image)
self.scheduleArray.append(newmodel)
})

}
case .failure(let error):
print(error.localizedDescription)
}
DispatchQueue.main.async {
self.tableView.reloadData()
}
}
}









share|improve this question













Could you help me please with this



I'm trying to pull data from API using Alamofire. Is it possible to pull simple data like ["title"] and Image in the same request and populate it in table view?



Here's my code:



Alamofire.request(baseURL).responseJSON { (response) in
switch response.result {
case .success:
if let value = response.result.value{
let json = JSON(value)
json.forEach({ (temp) in
let title = temp.1["title"].stringValue
let run = temp.1["run"].stringValue
let image = temp.1["thumb"].stringValue
let newmodel = Schedule(title: title, run: run, image: image)
self.scheduleArray.append(newmodel)
})

}
case .failure(let error):
print(error.localizedDescription)
}
DispatchQueue.main.async {
self.tableView.reloadData()
}
}
}






swift request alamofire






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 21 at 21:02









Акарыс Турганбекулы

36




36












  • "Is it possible to pull simple data like" - Yes, anything a HTTP server can produce, you can consume - which raises the questions over, what is the server responding with? You seem to trying to parse some JSON, is the server returning a JSON response? You question is to general and doesn't point to a specific problem or issue. Were you using a previous approach (URLSession?) which was working and this isn't? What URL are you communicating with? What are the inputs and expected outputs? Are you having trouble parsing the result or populating the table?
    – MadProgrammer
    Nov 21 at 21:06










  • Oh no, I don't have problem with populating data. I just wanted to write 1 Alamofire request for simple objects and image data as well
    – Акарыс Турганбекулы
    Nov 21 at 21:08










  • So you have, two requests to make that return different data sets and you want to some how combine them?
    – MadProgrammer
    Nov 21 at 21:10










  • Yes, something like Alamofire.request(baseURL).response { (response, error, data) in
    – Акарыс Турганбекулы
    Nov 21 at 21:12










  • This might be beyond the scope of your intention, but I'd consider looking something like "PromiseKit" or "Hydra", which would manage the execution of two async operations and a much more elegant way, other then using a bunch of semaphores and other locking/notification mechanisms ... just saying
    – MadProgrammer
    Nov 21 at 21:14


















  • "Is it possible to pull simple data like" - Yes, anything a HTTP server can produce, you can consume - which raises the questions over, what is the server responding with? You seem to trying to parse some JSON, is the server returning a JSON response? You question is to general and doesn't point to a specific problem or issue. Were you using a previous approach (URLSession?) which was working and this isn't? What URL are you communicating with? What are the inputs and expected outputs? Are you having trouble parsing the result or populating the table?
    – MadProgrammer
    Nov 21 at 21:06










  • Oh no, I don't have problem with populating data. I just wanted to write 1 Alamofire request for simple objects and image data as well
    – Акарыс Турганбекулы
    Nov 21 at 21:08










  • So you have, two requests to make that return different data sets and you want to some how combine them?
    – MadProgrammer
    Nov 21 at 21:10










  • Yes, something like Alamofire.request(baseURL).response { (response, error, data) in
    – Акарыс Турганбекулы
    Nov 21 at 21:12










  • This might be beyond the scope of your intention, but I'd consider looking something like "PromiseKit" or "Hydra", which would manage the execution of two async operations and a much more elegant way, other then using a bunch of semaphores and other locking/notification mechanisms ... just saying
    – MadProgrammer
    Nov 21 at 21:14
















"Is it possible to pull simple data like" - Yes, anything a HTTP server can produce, you can consume - which raises the questions over, what is the server responding with? You seem to trying to parse some JSON, is the server returning a JSON response? You question is to general and doesn't point to a specific problem or issue. Were you using a previous approach (URLSession?) which was working and this isn't? What URL are you communicating with? What are the inputs and expected outputs? Are you having trouble parsing the result or populating the table?
– MadProgrammer
Nov 21 at 21:06




"Is it possible to pull simple data like" - Yes, anything a HTTP server can produce, you can consume - which raises the questions over, what is the server responding with? You seem to trying to parse some JSON, is the server returning a JSON response? You question is to general and doesn't point to a specific problem or issue. Were you using a previous approach (URLSession?) which was working and this isn't? What URL are you communicating with? What are the inputs and expected outputs? Are you having trouble parsing the result or populating the table?
– MadProgrammer
Nov 21 at 21:06












Oh no, I don't have problem with populating data. I just wanted to write 1 Alamofire request for simple objects and image data as well
– Акарыс Турганбекулы
Nov 21 at 21:08




Oh no, I don't have problem with populating data. I just wanted to write 1 Alamofire request for simple objects and image data as well
– Акарыс Турганбекулы
Nov 21 at 21:08












So you have, two requests to make that return different data sets and you want to some how combine them?
– MadProgrammer
Nov 21 at 21:10




So you have, two requests to make that return different data sets and you want to some how combine them?
– MadProgrammer
Nov 21 at 21:10












Yes, something like Alamofire.request(baseURL).response { (response, error, data) in
– Акарыс Турганбекулы
Nov 21 at 21:12




Yes, something like Alamofire.request(baseURL).response { (response, error, data) in
– Акарыс Турганбекулы
Nov 21 at 21:12












This might be beyond the scope of your intention, but I'd consider looking something like "PromiseKit" or "Hydra", which would manage the execution of two async operations and a much more elegant way, other then using a bunch of semaphores and other locking/notification mechanisms ... just saying
– MadProgrammer
Nov 21 at 21:14




This might be beyond the scope of your intention, but I'd consider looking something like "PromiseKit" or "Hydra", which would manage the execution of two async operations and a much more elegant way, other then using a bunch of semaphores and other locking/notification mechanisms ... just saying
– MadProgrammer
Nov 21 at 21:14












1 Answer
1






active

oldest

votes

















up vote
0
down vote



accepted










You can get the base data at first and after that get every image with single request



get base data with this code :



 func POSTWithLoad(urlString: String,paramaters: [String: AnyObject]? = nil,success:@escaping (_ responseObject: AnyObject?) -> Void ,failure: @escaping (_ error: String?) -> Void ) {

Alamofire.request(baseUrlDev+urlString, method: .post, parameters:paramaters, encoding: URLEncoding.default, headers: headers).responseJSON(completionHandler: { (responseData) in

if (responseData.result.error == nil && responseData.result.isSuccess == true) {

//success

success(responseData)

} else {

//fauiler

failure("UnKnowen Data")

}

})
}


and use this for getImage :



func getImage(link : String , completion : @escaping (_ imageWithLink : (link : String,image : UIImage)) -> Void){
var image = UIImage(named: "placeholder")

URLSession.shared.dataTask(with: NSURL(string: link.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)!)! as URL, completionHandler: { (data, response, error) -> Void in
if error != nil {
print("errorLoadIamge : "+link)
//completion(image)
print(error)
return
}
DispatchQueue.main.async(execute: { () -> Void in
let mimage = UIImage(data: data!)
if(mimage != nil){
image = mimage!
completion((link : link , image : image))
print("successLoadIamge : "+link)
return
}
})

}).resume()
}


then can use it in your ViewContoller like this :



    let products : [Product] = 
let productImages : [String] =

POSTWithLoad(urlString: "YApiLink" , paramaters: requestParameters as [String : AnyObject]?, success: { (successObject) in

products = Mapper<Product>().mapArray(JSONObject : successObject)
productsImages =
print(successObject)

}, failure :{ (failureObject) in

print(failureObject)

}
)


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

let product = products[indexPath.row]
let cell = YourTableView.dequeueReusableCell(withIdentifier: "CellIdentifier", for: indexPath) as! YourTableViewCell

if let imageAndLink = productsImages.first(where: { $0.link == cell.product?.productImage})
{cell.pImage?.image = imageAndLink.image}
else{ cell.pImage.image = UIImage(named: "placeholder")
getImage(link: cell.product?.productImage ?? "", completion: {(newImage) in

DispatchQueue.main.async {
if self.productsImages.first(where: { $0.link == newImage.link}) == nil
{
self.productsImages.append(ProductImage(link : newImage.link , image : newImage.image) )
}
if cell.product?.productImage == newImage.link{
cell.pImage.image = newImage.image
}
}

})
}
}





share|improve this answer





















  • Thank you very much
    – Акарыс Турганбекулы
    Nov 22 at 14:03











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53420432%2falamofire-general-request%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
0
down vote



accepted










You can get the base data at first and after that get every image with single request



get base data with this code :



 func POSTWithLoad(urlString: String,paramaters: [String: AnyObject]? = nil,success:@escaping (_ responseObject: AnyObject?) -> Void ,failure: @escaping (_ error: String?) -> Void ) {

Alamofire.request(baseUrlDev+urlString, method: .post, parameters:paramaters, encoding: URLEncoding.default, headers: headers).responseJSON(completionHandler: { (responseData) in

if (responseData.result.error == nil && responseData.result.isSuccess == true) {

//success

success(responseData)

} else {

//fauiler

failure("UnKnowen Data")

}

})
}


and use this for getImage :



func getImage(link : String , completion : @escaping (_ imageWithLink : (link : String,image : UIImage)) -> Void){
var image = UIImage(named: "placeholder")

URLSession.shared.dataTask(with: NSURL(string: link.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)!)! as URL, completionHandler: { (data, response, error) -> Void in
if error != nil {
print("errorLoadIamge : "+link)
//completion(image)
print(error)
return
}
DispatchQueue.main.async(execute: { () -> Void in
let mimage = UIImage(data: data!)
if(mimage != nil){
image = mimage!
completion((link : link , image : image))
print("successLoadIamge : "+link)
return
}
})

}).resume()
}


then can use it in your ViewContoller like this :



    let products : [Product] = 
let productImages : [String] =

POSTWithLoad(urlString: "YApiLink" , paramaters: requestParameters as [String : AnyObject]?, success: { (successObject) in

products = Mapper<Product>().mapArray(JSONObject : successObject)
productsImages =
print(successObject)

}, failure :{ (failureObject) in

print(failureObject)

}
)


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

let product = products[indexPath.row]
let cell = YourTableView.dequeueReusableCell(withIdentifier: "CellIdentifier", for: indexPath) as! YourTableViewCell

if let imageAndLink = productsImages.first(where: { $0.link == cell.product?.productImage})
{cell.pImage?.image = imageAndLink.image}
else{ cell.pImage.image = UIImage(named: "placeholder")
getImage(link: cell.product?.productImage ?? "", completion: {(newImage) in

DispatchQueue.main.async {
if self.productsImages.first(where: { $0.link == newImage.link}) == nil
{
self.productsImages.append(ProductImage(link : newImage.link , image : newImage.image) )
}
if cell.product?.productImage == newImage.link{
cell.pImage.image = newImage.image
}
}

})
}
}





share|improve this answer





















  • Thank you very much
    – Акарыс Турганбекулы
    Nov 22 at 14:03















up vote
0
down vote



accepted










You can get the base data at first and after that get every image with single request



get base data with this code :



 func POSTWithLoad(urlString: String,paramaters: [String: AnyObject]? = nil,success:@escaping (_ responseObject: AnyObject?) -> Void ,failure: @escaping (_ error: String?) -> Void ) {

Alamofire.request(baseUrlDev+urlString, method: .post, parameters:paramaters, encoding: URLEncoding.default, headers: headers).responseJSON(completionHandler: { (responseData) in

if (responseData.result.error == nil && responseData.result.isSuccess == true) {

//success

success(responseData)

} else {

//fauiler

failure("UnKnowen Data")

}

})
}


and use this for getImage :



func getImage(link : String , completion : @escaping (_ imageWithLink : (link : String,image : UIImage)) -> Void){
var image = UIImage(named: "placeholder")

URLSession.shared.dataTask(with: NSURL(string: link.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)!)! as URL, completionHandler: { (data, response, error) -> Void in
if error != nil {
print("errorLoadIamge : "+link)
//completion(image)
print(error)
return
}
DispatchQueue.main.async(execute: { () -> Void in
let mimage = UIImage(data: data!)
if(mimage != nil){
image = mimage!
completion((link : link , image : image))
print("successLoadIamge : "+link)
return
}
})

}).resume()
}


then can use it in your ViewContoller like this :



    let products : [Product] = 
let productImages : [String] =

POSTWithLoad(urlString: "YApiLink" , paramaters: requestParameters as [String : AnyObject]?, success: { (successObject) in

products = Mapper<Product>().mapArray(JSONObject : successObject)
productsImages =
print(successObject)

}, failure :{ (failureObject) in

print(failureObject)

}
)


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

let product = products[indexPath.row]
let cell = YourTableView.dequeueReusableCell(withIdentifier: "CellIdentifier", for: indexPath) as! YourTableViewCell

if let imageAndLink = productsImages.first(where: { $0.link == cell.product?.productImage})
{cell.pImage?.image = imageAndLink.image}
else{ cell.pImage.image = UIImage(named: "placeholder")
getImage(link: cell.product?.productImage ?? "", completion: {(newImage) in

DispatchQueue.main.async {
if self.productsImages.first(where: { $0.link == newImage.link}) == nil
{
self.productsImages.append(ProductImage(link : newImage.link , image : newImage.image) )
}
if cell.product?.productImage == newImage.link{
cell.pImage.image = newImage.image
}
}

})
}
}





share|improve this answer





















  • Thank you very much
    – Акарыс Турганбекулы
    Nov 22 at 14:03













up vote
0
down vote



accepted







up vote
0
down vote



accepted






You can get the base data at first and after that get every image with single request



get base data with this code :



 func POSTWithLoad(urlString: String,paramaters: [String: AnyObject]? = nil,success:@escaping (_ responseObject: AnyObject?) -> Void ,failure: @escaping (_ error: String?) -> Void ) {

Alamofire.request(baseUrlDev+urlString, method: .post, parameters:paramaters, encoding: URLEncoding.default, headers: headers).responseJSON(completionHandler: { (responseData) in

if (responseData.result.error == nil && responseData.result.isSuccess == true) {

//success

success(responseData)

} else {

//fauiler

failure("UnKnowen Data")

}

})
}


and use this for getImage :



func getImage(link : String , completion : @escaping (_ imageWithLink : (link : String,image : UIImage)) -> Void){
var image = UIImage(named: "placeholder")

URLSession.shared.dataTask(with: NSURL(string: link.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)!)! as URL, completionHandler: { (data, response, error) -> Void in
if error != nil {
print("errorLoadIamge : "+link)
//completion(image)
print(error)
return
}
DispatchQueue.main.async(execute: { () -> Void in
let mimage = UIImage(data: data!)
if(mimage != nil){
image = mimage!
completion((link : link , image : image))
print("successLoadIamge : "+link)
return
}
})

}).resume()
}


then can use it in your ViewContoller like this :



    let products : [Product] = 
let productImages : [String] =

POSTWithLoad(urlString: "YApiLink" , paramaters: requestParameters as [String : AnyObject]?, success: { (successObject) in

products = Mapper<Product>().mapArray(JSONObject : successObject)
productsImages =
print(successObject)

}, failure :{ (failureObject) in

print(failureObject)

}
)


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

let product = products[indexPath.row]
let cell = YourTableView.dequeueReusableCell(withIdentifier: "CellIdentifier", for: indexPath) as! YourTableViewCell

if let imageAndLink = productsImages.first(where: { $0.link == cell.product?.productImage})
{cell.pImage?.image = imageAndLink.image}
else{ cell.pImage.image = UIImage(named: "placeholder")
getImage(link: cell.product?.productImage ?? "", completion: {(newImage) in

DispatchQueue.main.async {
if self.productsImages.first(where: { $0.link == newImage.link}) == nil
{
self.productsImages.append(ProductImage(link : newImage.link , image : newImage.image) )
}
if cell.product?.productImage == newImage.link{
cell.pImage.image = newImage.image
}
}

})
}
}





share|improve this answer












You can get the base data at first and after that get every image with single request



get base data with this code :



 func POSTWithLoad(urlString: String,paramaters: [String: AnyObject]? = nil,success:@escaping (_ responseObject: AnyObject?) -> Void ,failure: @escaping (_ error: String?) -> Void ) {

Alamofire.request(baseUrlDev+urlString, method: .post, parameters:paramaters, encoding: URLEncoding.default, headers: headers).responseJSON(completionHandler: { (responseData) in

if (responseData.result.error == nil && responseData.result.isSuccess == true) {

//success

success(responseData)

} else {

//fauiler

failure("UnKnowen Data")

}

})
}


and use this for getImage :



func getImage(link : String , completion : @escaping (_ imageWithLink : (link : String,image : UIImage)) -> Void){
var image = UIImage(named: "placeholder")

URLSession.shared.dataTask(with: NSURL(string: link.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)!)! as URL, completionHandler: { (data, response, error) -> Void in
if error != nil {
print("errorLoadIamge : "+link)
//completion(image)
print(error)
return
}
DispatchQueue.main.async(execute: { () -> Void in
let mimage = UIImage(data: data!)
if(mimage != nil){
image = mimage!
completion((link : link , image : image))
print("successLoadIamge : "+link)
return
}
})

}).resume()
}


then can use it in your ViewContoller like this :



    let products : [Product] = 
let productImages : [String] =

POSTWithLoad(urlString: "YApiLink" , paramaters: requestParameters as [String : AnyObject]?, success: { (successObject) in

products = Mapper<Product>().mapArray(JSONObject : successObject)
productsImages =
print(successObject)

}, failure :{ (failureObject) in

print(failureObject)

}
)


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

let product = products[indexPath.row]
let cell = YourTableView.dequeueReusableCell(withIdentifier: "CellIdentifier", for: indexPath) as! YourTableViewCell

if let imageAndLink = productsImages.first(where: { $0.link == cell.product?.productImage})
{cell.pImage?.image = imageAndLink.image}
else{ cell.pImage.image = UIImage(named: "placeholder")
getImage(link: cell.product?.productImage ?? "", completion: {(newImage) in

DispatchQueue.main.async {
if self.productsImages.first(where: { $0.link == newImage.link}) == nil
{
self.productsImages.append(ProductImage(link : newImage.link , image : newImage.image) )
}
if cell.product?.productImage == newImage.link{
cell.pImage.image = newImage.image
}
}

})
}
}






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 21 at 22:31









Ammar

976




976












  • Thank you very much
    – Акарыс Турганбекулы
    Nov 22 at 14:03


















  • Thank you very much
    – Акарыс Турганбекулы
    Nov 22 at 14:03
















Thank you very much
– Акарыс Турганбекулы
Nov 22 at 14:03




Thank you very much
– Акарыс Турганбекулы
Nov 22 at 14:03


















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53420432%2falamofire-general-request%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Catalogne

Violoncelliste

Héron pourpré