Parse JSON network list into Network objects for the view

This commit is contained in:
Grant Limberg
2016-05-17 19:41:54 -07:00
parent da30d2898e
commit d5620288d5
5 changed files with 151 additions and 49 deletions

View File

@@ -12,7 +12,7 @@ class ServiceCom: NSObject {
static let baseURL = "http://localhost:9993"
static var key: NSString? = "ddeb3b1e6996b6b4f2d12d10"
static func getNetworkList() {
static func getNetworkList(completionHandler: ([Network]) -> Void) {
let urlString = baseURL + "/network?auth=\(ServiceCom.key!)"
@@ -27,11 +27,16 @@ class ServiceCom: NSObject {
if status == 200 {
do {
let json = try NSJSONSerialization.JSONObjectWithData(data!, options: NSJSONReadingOptions())
print("\(json)")
let json = try NSJSONSerialization.JSONObjectWithData(data!, options: NSJSONReadingOptions()) as! [[String: AnyObject]]
var networks = [Network]()
for jobj in json {
networks.append(Network(jsonData: jobj))
}
completionHandler(networks)
}
catch {
print("JSON Error: \(error)")
}
}
}