mercredi 28 janvier 2015

Why can't I get the request result form Alamofire


Vote count:

0




I can't get the result of Alamofire request.So,I created ouput of an array that I got from json async call.I can't get the resultArray out of dispatch {...}.When I add println to debug the code.The second one appear first before the first one. All i want to resultArray to get the data from Alamofire to display in UIPickerView.Please Help!!!


Here is my code



import UIKit
import Alamofire

class ViewController: UIViewController , UIPickerViewDelegate, UIPickerViewDataSource{

@IBOutlet var venuePicker : UIPickerView?

var result = [String:String]()

var resultArray = [String]()

let refreshControl = UIRefreshControl()

var populatingVenues = false

override func viewDidLoad() {

populateVenue()
println("The 2st result array : \(self.resultArray)" )
}

func numberOfComponentsInPickerView(pickerView: UIPickerView) -> Int {
return 1
}

func pickerView(pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
return resultArray.count
}

func pickerView(pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String! {

return resultArray[row]
}

func populateVenue(){

if populatingVenues{
return
}

populatingVenues = true

Alamofire.request(.POST, "http://localhost:8080/ws/automobile/global/auction/latest/venues").responseJSON() {
(_, _, jsonData, error) in

if error == nil {

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0)){
var venues = JSON(jsonData!)

let d = venues.dictionaryValue

for (k, v) in venues {
self.result[k] = v.arrayValue[0].stringValue
}
self.resultArray = self.result.values.array
println("The 1st result array : \(self.resultArray)" )
}
}
else{
println("Errror")
}
self.populatingVenues = false
}
self.venuePicker?.delegate = self
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}


}


Here is my output at console



The 2st result array : []
The 1st result array : [ORIX Kobe Nyusatsu, NPS Sendai Nyusatsu, JU Gunma, KAA Kyoto, JU Ibaraki, USS Gunma, ISUZU Kobe, NAA Osaka Nyusatsu, SMAP Sapporo Nyusatsu, L-Up PKobeNyusatsu, ARAI Sendai, TAA Minami Kyushu, NPS Oyama Nyusatsu, CAA Tokyo, JU Toyama, USS Shikoku, NPS Gifu Nyusatsu, NAA Fukuoka, KCAA Yamaguchi, JU Fukuoka, LAA Kansai, JAA, TAA Kinki, USS Sapporo, JU Miyagi, USS Fukuoka, JU Tokyo, USS Nagoya, HONDA Fukuoka, NAA Nagoya, BayAuc, AUCNET, SMAP Tokyo Nyusatsu, HAA Osaka, HONDA Hokkaido, JU Ishikawa, JU Mie, USS Saitama, JU Hiroshima, CAA Tohoku, SAKURA Nyusatsu, USS Kyushu, NPS Osaka Nyusatsu, JU Gifu, KCAA Ebino, JU Sapporo, JU Yamaguchi, JU Yamanashi, NPS Fukuoka Nyusatsu, SAA Sapporo, TAA Chubu, NPS Tokyo Nyusatsu, NAA Tokyo, NAA Osaka, SMAP Fukuoka Nyusatsu, USS Tokyo, KCAA Fukuoka, SAA Hamamatsu, JU Kanagawa, ARAI Oyama, HAA Kobe, NPS Tomakomai Nyusatsu, USS Shizuoka, ARAI Bay Side, USS Osaka, TAA Kantou, ARAI Oyama VT, JU Niigata, LAA Shikoku, USS Tohoku, SMAP Nagoya Nyusatsu, USS Kobe, SLC Kyushu Nyusatsu, JU Okinawa, JU Chiba, CAA Gifu, USSR Nagoya, JU Kushiro, ISUZU Kyushu, L-Up PTokyoNyusatsu, Hero, LAA Okayama, TAA Hokkaido]


Please i really need to know what is happening to me and why i can't get the result of async call first.



asked 31 secs ago







Why can't I get the request result form Alamofire

Aucun commentaire:

Enregistrer un commentaire