So I\'m fetching data from a url which is in a json format. I\'m trying to display the data in my tableview but, even though it feels simple, I can\'t figure out how to do it.<
Well first change the function to return your company array :
func getJSON() -> NSMutableArray {
}
By the end of the for loop return the company array
for company in companies {
}
After your array is populated, return the array inside this block:
dispatch_async(dispatch_get_main_queue(), {
return companyArray
})
And after task.resume()
return the array:
return companyArray
From anywhere you wanna call this class and get the array :
Get a reference of the class
Let companyModal = CompanyModel()
And in anywhere you have your table view and the class let's say in viewDidLoad
, you should first have NSMutableArray
.
var arraySource = NSMutableArray()
And in viewDidLoad
:
arraySource = companyModal.getJSON()
And to show the data in tableView do :
Mytableview.reloadData()