Created
April 10, 2017 04:02
-
-
Save farhan-syed/7ef31c53605e6a0ebdb8fe3585419ce8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func parseJSON () { | |
let url = URL(string: "https://api.myjson.com/bins/vi56v") | |
let task = URLSession.shared.dataTask(with: url!) {(data, response, error ) in | |
guard error == nil else { | |
print("returned error") | |
return | |
} | |
guard let content = data else { | |
print("No data") | |
return | |
} | |
guard let json = try? JSONSerialization.jsonObject(with: content, options: JSONSerialization.ReadingOptions.mutableContainers) as! NSDictionary else { | |
return | |
} | |
let array = json["companies"] as? NSMutableArray | |
for item in array! { | |
let company = item as? String | |
self.tableArray.append(company!) | |
} | |
print(self.tableArray) | |
DispatchQueue.main.async { | |
self.tableView.reloadData() | |
} | |
} | |
task.resume() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment