2017-01-15 4 views
0

최근에 Swift으로 마이그레이션 했으므로 참을성과지지를 보내 주시기 바랍니다. 내가 Alamofire 4Alamofire 4의 Swift 3 Alamofire 버전에 대한 ObjectMapper 및 Alamofire 문제

let URL = "https://raw.githubusercontent.com/tristanhimmelman/AlamofireObjectMapper/d8bb95982be8a11a2308e779bb9a9707ebe42ede/sample_json" 
Alamofire.request(URL).response { (response: DataResponse<WeatherResponse>) in 

    let weatherResponse = response.result.value 
    print(weatherResponse?.location) 

    if let threeDayForecast = weatherResponse?.threeDayForecast { 
     for forecast in threeDayForecast { 
      print(forecast.day) 
      print(forecast.temperature)   
     } 
    } 
} 

의 구문을 수정 Object Mappergithub page의 코드를 사용하지만, 스크린 샷과 같이 나는 다음과 같은 오류가 발생합니다. 당신이 Alamofire에서 메서드를 호출해야

ScreenShot

답변

0

이 방법 :

func getWeatherDataResponseFromServer() { 

     let URL = "https://raw.githubusercontent.com/tristanhimmelman/AlamofireObjectMapper/d8bb95982be8a11a2308e779bb9a9707ebe42ede/sample_json" 

     //AlamoFire request 
     Alamofire.request(URL, method: .get, parameters: nil, encoding: JSONEncoding.default, headers: nil).responseJSON { response in 
      do { 

       let reponse = try JSONSerialization.jsonObject(with: response.data!, options: JSONSerialization.ReadingOptions()) as! Dictionary<String, AnyObject> 

      } catch { 
       print(error) 
      } 
     } 
    } 

희망이 거 당신을 도울.

+0

올바른 형식을 얻을 수 있도록 도와 주셔서 감사하지만 완성시 응답을 모델링해야합니다. https://github.com/tristanhimmelman/AlamofireObjectMapper –

+0

다음에 데이터를 반환하는 완성 처리기 메서드를 만들어야합니다. 귀하의 형식을 –

+0

같아요 반환 된 자동으로 모델 클래스에 기록됩니다 –