Skip to content

Instantly share code, notes, and snippets.

@aGupieWare
aGupieWare / swift_client_request_item.txt
Created November 17, 2014 03:18
Swift client, request item . . .
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 //
@aGupieWare
aGupieWare / swift_client_url_for_item_with_description.txt
Created November 17, 2014 03:16
Swift client, url for item with description . . .
// 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"
@aGupieWare
aGupieWare / swift_client_view_did_appear.txt
Created November 17, 2014 03:12
Swift client, viewDidAppear, item description . . .
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
})
@aGupieWare
aGupieWare / swift_client_item_description_funcs.txt
Created November 17, 2014 03:09
Swift client, item description funcs . . .
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
// title and download //
}
// MARK: - Ancillary Methods
func urlForItemWithDescription(itemID : String) -> (NSURL?) {
// request endpoint for item //
@aGupieWare
aGupieWare / swift_client_prepare_for_segue.txt
Created November 17, 2014 03:07
Swift client, final prepare for segue . . .
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
@aGupieWare
aGupieWare / swift_client_default_navigation_code.txt
Created November 17, 2014 03:05
Swift client, default navigation code . . .
/*
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject!) {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
@aGupieWare
aGupieWare / swift_client_item_view_snippet.txt
Created November 17, 2014 02:56
Swift client, item view snippet . . .
@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)
@aGupieWare
aGupieWare / swift_client_compare_index.txt
Created November 14, 2014 22:02
Swift client, comapre index . . .
currentIndex?.item == capturedIndex!.item
@aGupieWare
aGupieWare / swift_client_current_index.txt
Created November 14, 2014 22:00
Swift client, current index . . .
let currentIndex = tableView.indexPathForCell(cell)
@aGupieWare
aGupieWare / swift_client_item_image.txt
Created November 14, 2014 21:59
Swift client, item image . . .
let itemImage = UIImage(data:imageData!)