Last active
April 11, 2017 19:43
-
-
Save farhan-syed/b6b43273565d449e86e1fc138aff6a54 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("returning error") | |
return | |
} | |
guard let content = data else { | |
print("not returning data") | |
return | |
} | |
guard let json = (try? JSONSerialization.jsonObject(with: content, options: JSONSerialization.ReadingOptions.mutableContainers)) as? [String: Any] else { | |
print("Not containing JSON") | |
return | |
} | |
if let array = json["companies"] as? [String] { | |
self.tableArray = array | |
} | |
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