- 发送请求
// 引入
import AlamofireObjectMapper
// 在方法里如下写入
var articles = [Article]()
Alamofire.request("https://cloudgym.sharecircle.cn/api/v1/news/front").responseArray { [weak self] (response: DataResponse<[Article]>) in
let articleArray = response.result.value
if let articleArray = articleArray {
articles = articleArray
}
self?.tableView.reloadData()
}
- 定义Article模型类,实现Map对应关系
import ObjectMapper
class Article: Mappable {
var nid: String?
var title: String?
var source: String?
var time: String?
var coverImage: UIImage?
required init?(map: Map) {
}
public func mapping(map: Map) {
nid <- map["nid"]
title <- map["title"]
source <- map["columns"]
time <- map["created"]
coverImage <- map["cover"]
}
}
详见https://github.com/tristanhimmelman/AlamofireObjectMapper
里有format对象以及对象数组
网友评论