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
| // MARK: - Networking | |
| func requestInventory(endPointURL : String, responseHandler : (error : NSError? , items : Array<PlumbingSupplyItem>?) -> () ) -> () { | |
| // Url session request goes here // | |
| responseHandler( error: nil, items: nil) | |
| } |
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
| override func viewDidAppear(animated: Bool) { | |
| super.viewDidAppear(animated) | |
| self.requestInventory(self.inventoryUrlEndpoint, { (error, items) -> () in | |
| // present processed url session response results to the user –- update UI code // | |
| }) | |
| } |
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
| let url:NSURL = NSURL(string: endPointURL)! | |
| let task = self.urlSession.dataTaskWithURL(url, completionHandler: { (data, response, error) -> Void in | |
| println(response) | |
| responseHandler( error: nil, items: nil) | |
| }) | |
| task.resume() |
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
| var jsonParseError: NSError? | |
| var jsonResult = NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions.MutableContainers, error: &jsonParseError) as NSDictionary | |
| println(jsonResult) |
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 inventoryItems(data: NSData) -> (Array<PlumbingSupplyItem>) { | |
| var jsonParseError: NSError? | |
| var jsonResult = NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions.MutableContainers, error: &jsonParseError) as NSDictionary | |
| return [jsonResult] | |
| } |
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
| var inventoryItems = self.inventoryItems(data) | |
| println(inventoryItems) |
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
| var rawInventoryItems = jsonResult["data"] as Array<Dictionary<String,String>> | |
| var refinedInventoryItems : Array<PlumbingSupplyItem> = [] | |
| for itemDict in rawInventoryItems { | |
| var item : PlumbingSupplyItem = PlumbingSupplyItem(bsn_id: itemDict["id"], bsn_name: itemDict["name"], bsn_image: itemDict["image"], bsn_description: itemDict["description"]) | |
| refinedInventoryItems.append(item) | |
| } | |
| return refinedInventoryItems |
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
| var dataSource : Array<PlumbingSupplyItem> = [] |
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
| override func numberOfSectionsInTableView(tableView: (UITableView!)) -> Int { | |
| // Return the number of sections. | |
| return 1 | |
| } | |
| override func tableView(tableView: (UITableView!), numberOfRowsInSection section: Int) -> Int { | |
| // Return the number of rows in the section. | |
| return self.dataSource.count | |
| } | |
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
| self.dataSource = self.inventoryItems(data) | |
| dispatch_async(dispatch_get_main_queue()!, { () -> Void in | |
| self.tableView.reloadData() | |
| self.webActivityIndicator.hidden = true | |
| }) |