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
@IBAction func snapBarButtonItemTapped(sender: UIBarButtonItem) { | |
if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.Camera){ | |
var cameraController = UIImagePickerController() | |
cameraController.delegate = self | |
cameraController.sourceType = UIImagePickerControllerSourceType.Camera | |
let mediaTypes:[AnyObject] = [kUTTypeImage] | |
cameraController.mediaTypes = mediaTypes | |
} |
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 alertController = UIAlertController(title: "Alert", message: "Your device does not support camera or photo libary", preferredStyle: UIAlertControllerStyle.Alert) | |
alertController.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler: nil)) | |
self.presentViewController(alertController, animated: true, completion: 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
//Withing APP Delegate | |
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { | |
// Override point for customization after application launch. | |
let cache = NSURLCache(memoryCapacity: 8 * 1024 * 1024, diskCapacity: 20 * 1024 * 1024, diskPath: nil) | |
NSURLCache.setSharedURLCache(cache) | |
return true | |
} |
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 applicationDidReceiveMemoryWarning(application: UIApplication) { | |
NSURLCache.sharedURLCache().removeAllCachedResponses() | |
} |
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
(UIApplication.sharedApplication().delegate as AppDelegate).saveContext() |
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
hdiutil makehybrid -o ~/Desktop/image.iso ~/path/to/folder/to/be/converted -iso -joliet |
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 request = NSMutableURLRequest(URL: NSURL(string: "https://api.nutritionix.com/v1_1/search/")!) | |
let session = NSURLSession.sharedSession() | |
request.HTTPMethod = "POST" | |
var params = [ | |
"appId" : kAppId, | |
"appKey" : kAppKey, | |
"fields" : ["item_name", "brand_name", "keywords", "usda_fields"], | |
"limit" : "50", | |
"query" : searchString, | |
"filters": ["exists":["usda_fields": true]] |
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
$.fn.serializeObject = function () { | |
var o = {}; | |
var a = this.serializeArray(); | |
$.each(a, function () { | |
if (o[this.name] !== undefined) { | |
if (!o[this.name].push) { | |
o[this.name] = [o[this.name]]; | |
} | |
o[this.name].push(this.value || ''); | |
} else { |
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
1/ 1 object to represent the whole set of app data | |
2/ State is read only | |
3/ Pure functions dont modify arguments and dont rely on anytihng other than arguments passed to them to calculate | |
4/ UI is a representation of application state, | |
5/ State changes use pure functions so you take the existing state and the action to calculate a new state from, then pass that back. (testable and predictable). The new state can still reference old objects that made up the previous state if these have not been modified | |
6/ Reducer function takes the state and action arguments to create new state. (an action is the minimum set of arguments needed to create a new state object from its previous state | |
7/ If reducer recieved undefined as its stateargument it must return what is to be considered the inital state of the application | |
8/ If a reducer recieves an unknow action it mus return the existing state |
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
this varies depending on the execution context and can sometimes lead to unexpected behaviour | |
ways of tackling this are: | |
newname = functionname.bind(object); // calling the bind method which exists on all JS functions creates a copy of the function | |
// with this scoped to the value of the object passed into the bind method. | |
newname(arg1,arg2); // newname will then need to be executed | |