【发布时间】:2015-11-12 18:52:09
【问题描述】:
由于很多人都有这个错误,我也有,我不知道为什么“responseObject 不能使用类型为 ((JSONResponse>) -> _) 的参数列表调用”
我也在使用 Alamofire+ObjectMapper 的 JSON 映射
有人知道,Alamofire 有什么问题,经常出错,可能是关于理解 Alamofire 的任何想法?
import Foundation
import Alamofire
import AlamofireObjectMapper
import ObjectMapper
public protocol Mappable {
static func newInstance(map: Map) -> Mappable?
mutating func mapping(map: Map)
}
class JMapping {
func getJSON() {
let url = "http://www.somestringToJson/json.json"
Alamofire
.request(.GET, url, parameters: nil)
.responseObject { (response: JSONResponse?) in
println(response?.title)
if let events = response?.events {
for event in events {
println(event.id)
println(event.title)
}
}
}
}
}
class JSONResponse: Mappable {
var title: String?
var id: String?
var events: [EventsResponse]?
class func newInstance(map: Map) -> Mappable? {
return JSONResponse()
}
func mapping(map: Map) {
title <- map["title"]
id <- map["id"]
events <- map["events"]
}
}
class EventsResponse: Mappable {
var title: String?
var id: String?
var content: [ContentResponse]?
class func newInstance(map:Map) -> Mappable? {
return EventsResponse()
}
func mapping(map: Map) {
title <- map["title"]
id <- map["id"]
content <- map["content"]
}
}
class ContentResponse: Mappable{
var content_type: String?
var visible: Bool?
var data: NSArray?
class func newInstance(map: Map) -> Mappable? {
return ContentResponse()
}
func mapping(map: Map) {
content_type <- map["content_type"]
visible <- map["visible"]
data <- map["data"]
}
}
【问题讨论】:
-
其实
.responseObject { (response: JSONResponse?, error: NSError?) in....也不行 -
我也试过这个
.responseObject { (_, response: JSONResponse?, _, error: NSError?) in
标签: ios json swift mapping alamofire