2015-07-22 28 views
0

任何人都可以解釋爲什麼我的請求到以下AlamoFire請求的URL只適用於我的viewDidLoad()方法嗎?AlamoFire request()只能在viewDidLoad()中工作

request(.GET, URLString: "https://mySecureUrl") 
     .responseJSON { (_, _, json, error) in 

       let jsonEntries = JSON(json!) 
    } 

我已將AlamoFire swift文件添加到我的項目中。每當我上面的代碼行添加到任何方法,我從來沒有下面的代碼

let jsonEntries = JSON(json!) 

該計劃剛剛跳過的responseJSON乾脆。任何想法爲什麼?

回答

0

如果使用Swift2必須使用Alamofire swift2分支從他github上:https://github.com/Alamofire/Alamofire/tree/swift-2.0

而且作爲Alamofire自述文件中提到,JSON響應被封裝在結果參數是這樣的:

Alamofire.request(.GET, "http://httpbin.org/get") 
     .responseJSON { _, _, result in 
      print("Response JSON: \(result.value)") 
     } 
相關問題