How to fix array of memory leaks on AlamofireObjectMapper
How can I solve the leak that occurred in the below example code as shown in this image:
import UIKit
import Alamofire
import AlamofireObjectMapper
class ViewController: UIViewController {
@IBAction func action(_ sender: Any) {
load { (posts: [Post]) in
posts.map({ (post: Post) -> Void in
print(post.title)
})
}
}
func load( posts: (([Post]) -> Void)!) {
let urlString = "https://jsonplaceholder.typicode.com/posts"
let url = try! urlString.asURL()
Alamofire.request(url).validate().responseArray { (response: DataResponse<[Post]>) in
guard let postArray = response.result.value else {return}
posts(postArray)
}
}
}
+3
source to share
No one has answered this question yet
Check out similar questions: