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 task = self.urlSession.dataTaskWithURL(endPointURL!, completionHandler: { (data, response, error) -> Void in | |
| // convert the JSON response data into a NSDictionary // | |
| var jsonParseError: NSError? | |
| var jsonResult = NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions.MutableContainers, error: &jsonParseError) | |
| as NSDictionary | |
| var rawInventoryItems = jsonResult["data"] as Dictionary<String,String> | |
| dispatch_async(dispatch_get_main_queue()!, { () -> Void in | |
| // call our completion handler // |
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
| // extract the first two characters of an item's id // | |
| let rangeOfHello = Range(start: itemID.startIndex, end: advance(itemID.startIndex, 2)) | |
| let prefixItemID = itemID.substringWithRange(rangeOfHello) | |
| var url : NSURL? | |
| switch prefixItemID | |
| { | |
| case "PT": | |
| let filePath : String = "http://localhost:8888/api/v1/plumbing_tools/\(itemID).json" |
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.title = self.bsn_plumbingItem!.bsn_name | |
| let url : NSURL? = self.urlForItemWithDescription(self.bsn_plumbingItem!.bsn_id!) | |
| self.requestItem(url, responseHandler: { (error, itemDescription) -> () in | |
| self.bsn_textView.text = itemDescription | |
| }) |
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) | |
| // title and download // | |
| } | |
| // MARK: - Ancillary Methods | |
| func urlForItemWithDescription(itemID : String) -> (NSURL?) { | |
| // request endpoint for item // |
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 destViewController = segue.destinationViewController as PlumbingSupplyItemDescriptionViewController | |
| let selectedCell = sender as UITableViewCell | |
| let selectedIndex = self.tableView.indexPathForCell(selectedCell) | |
| destViewController.bsn_plumbingItem = self.dataSource[selectedIndex!.row] | |
| destViewController.bsn_capturedImage = selectedCell.imageView.image |
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
| @IBOutlet weak var bsn_imageView: UIImageView! | |
| @IBOutlet weak var bsn_textView: UITextView! | |
| var bsn_plumbingItem: PlumbingSupplyItem? | |
| var bsn_capturedImage: UIImage? | |
| var urlSession = NSURLSession.sharedSession() | |
| let backgroundQueue : dispatch_queue_t = dispatch_queue_create("com.aGupieWare.SwiftNetworking.backgroundQueue", 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
| currentIndex?.item == capturedIndex!.item |
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 currentIndex = tableView.indexPathForCell(cell) |
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 itemImage = UIImage(data:imageData!) |