I was doing the JSON Parsing in Swift tutorial by Ray Wenderlich.
While using DataManager.getTopAppsDataFromAppsWithSuccess in viewDidLoad(), Its unable to print out the array when its outside the DataManager block.
Does someone know how to get the array values outside that block ?
Code :
var apps = [String]()
override func viewDidLoad() {
DataManager.getTopAppsDataFromAppsWithSuccess { (ByodData) -> Void in
let json = JSON(data: ByodData)
if let appArray = json.array{
for appDict in appArray {
var appName: String = appDict["name"].stringValue
self.apps.append(appName)
}
}
println(self.apps)
}
Input JSON:
[
{
"id":1,
"name":"AdobeReader",
"url":"comp2014group1.herokuapp.com/apps/1.json";
},
{
"id":2,
"name":"BBCiPlayer",
"url":"comp2014group1.herokuapp.com/apps/2.json";
},
{
"id":3,
"name":"BBCNews",
"url":"comp2014group1.herokuapp.com/apps/3.json";
},
{
"id":4,
"name":"BBCWeather",
"url":"comp2014group1.herokuapp.com/apps/4.json";
}
]
Output :
[]
printlnstatement too soon for the data to be loaded.