如何修复AlamofireObjectMapper上的内存泄漏数组

时间:2017-05-03 12:09:36

标签: swift alamofire objectmapper

如何解决下面示例代码中发生的泄漏,如下图所示:enter image description here

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)
    }
 }
}

0 个答案:

没有答案