tristanhimmelman / AlamofireObjectMapper

An Alamofire extension which converts JSON response data into swift objects using ObjectMapper
MIT License
2.66k stars 474 forks source link

Generics Array problem #113

Closed oncity closed 8 years ago

oncity commented 8 years ago

json data {"dateline":123,"data":[{"tid":1466218037,"subject":"time is"},{"tid":123,"subject":"catcat"}]}

class NewsNode: Mappable {
    var tid: Int?
    var subject: String?
    required init?(_ map: Map) {
    }

    func mapping(map: Map) {
        tid    <- map["tid"]
        subject <- map["subject"]
    }
}

class BaseList<T>: Mappable {
    var dateline: Int?
    var data: [T]?
    required init?(_ map: Map) {
    }

    func mapping(map: Map) {
        dateline <- map["dateline"]
        data <- map["data"]
    }
}

        Alamofire.request(.GET, URL).responseObject { (response: Response< BaseList<NewsNode>, NSError>) in
            let dd = response.result.value
            print(dd?.data)
        }

data is nil

if change to var data: [NewsNode]? is work

help

oncity commented 8 years ago

have fix

class BaseList<T:Mappable>: Mappable