, ObjectMapper lib.
Github ObjectMapper.
, lib:
IntBoolDoubleFloatStringRawRepresentable ()Array<AnyObject>Dictionary<String, AnyObject>Object<T: Mappable>Array<T: Mappable>Array<Array<T: Mappable>>Set<T: Mappable>Dictionary<String, T: Mappable>Dictionary<String, Array<T:Mappable>>
, , nil.
var location: CLLocation?.
CLLocation, CustomCLLocation :
JSON ( Json, )
"location":{
"long": 43.666,
"lat": 73.4
}
Swift: "CustomCLLocation", , , CLLocation Json
var latitude: Double?
var longitude: Double?
required init?(_ map: Map) {
mapping(map)
}
func mapping(map: Map) {
longitude <- map["long"]
latitude <- map["lat"]
}
"" CLLocation: var location: CustomCLLocation?
, CLLocation. ( CustomCLLocation):
extension CLLocation {
public class func createFromCustomCLLocation(custom: CustomCLLocation) -> CLLocation {
return self.init(custom.latitude,custom.longitude)
}
}
:
var locationCLL = CLLocation.createFromCustomCLLocation(location)
: Alamofire Request
AlamofireObjectMapper ios 8.0 +
Alamofire.request(.GET, UrlEndpoints.branchUrl()).responseArray { (response: [BranchObjectMapper]?, error : ErrorType?) in
if(error != nil) {
print(error)
}else{
print("data downloaded")
if let response = response {
branchList(response)
for branch in self.branchList {
print(branch.id)
print(branch.name)
}
}
}
}