클래스가 의미가 있다면, 클래스가 될 자격이 있습니다. 따라서 직렬화 및 구문 분석 클래스는 내 생각에 클래스가되어야합니다. 잘 어울린다.
슬프게도이 목적을 위해 작성한 프레임 워크가있어서 쉽게 처리 할 수 있습니다. 예를 들어, "ObjectMapper"에는 "AlamofireObjectMapper"라는 확장명이 있습니다.
https://github.com/tristanhimmelman/AlamofireObjectMapper
그리고 당신과 같이 사용할 수 있습니다 :
let URL = "https://raw.githubusercontent.com/tristanhimmelman/AlamofireObjectMapper/d8bb95982be8a11a2308e779bb9a9707ebe42ede/sample_json"
Alamofire.request(.GET, URL).responseObject { (response: Response<WeatherResponse, NSError>) in
let weatherResponse = response.result.value
print(weatherResponse?.location)
if let threeDayForecast = weatherResponse?.threeDayForecast {
for forecast in threeDayForecast {
print(forecast.day)
print(forecast.temperature)
}
}
}