I m new to iOS and Swift development environment. I was trying to use Alamofire for pulling JSON and AlamofireObjectMapper for Mapping the retrieved JSON collections back to my Swift Object.
The issue is I m able to fetch the JSON thru Alamofire request and the count is shown, but the mapping part seems to be showing nil. Is something I had been missed out . Appreciate help.
Model Class
import UIKit
import CoreLocation
import ObjectMapper
class BranchObjectMapper : Mappable {
// MARK: Properties
var id: Int?
var cityId: Int?
var areaId: Int?
var name: String?
var nameAr: String?
var branchAddr: String?
var branchAddr2: String?
var location: CLLocation?
required init?(_ map: Map) {
mapping(map)
}
func mapping(map: Map) {
id <- map["id"]
cityId <- map["cityId"]
areaId <- map["areaId"]
name <- map["name"]
nameAr <- map["nameAr"]
branchAddr <- map["branchAddr"]
branchAddr2 <- map["branchAddr2"]
location <- map["location"]
}
}
Request part in viewDidLoad()
Alamofire.request(.GET, UrlEndpoints.branchUrl()).responseArray { (response: Response<[BranchObjectMapper], NSError>) in
self.branchList = response.result.value!
print(self.branchList.count) // count is correct
for branch in self.branchList {
print(branch.id) // prints nil
print(branch.id) // prints nil
}
}
Thanks in advance
The complete JSON response looks like below. Have constructed only needed ones in Model.
[{"Id":"16","areaId":"17","name":"Al Aqiq”,”cityId”:4”,”Zip":"","nameAr":"\u0637\u0631\u064a\u0642 \u0627\u0644\u0645","branchAddr":"test","branchAddr2":"test"Latitude":"24.60425","Longitude":"46.629631","cityId":"1"}]