Skip to content

Instantly share code, notes, and snippets.

@perlmunger
Created April 27, 2016 15:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save perlmunger/a443d737b192b2e19606df70a9206338 to your computer and use it in GitHub Desktop.
Save perlmunger/a443d737b192b2e19606df70a9206338 to your computer and use it in GitHub Desktop.
// ImagePicker encapsulates UIImagePickerViewController functioality providing a convenient
// closure interface for responding to user interactions
import UIKit
import MobileCoreServices
class ImagePicker : NSObject, UINavigationControllerDelegate, UIImagePickerControllerDelegate {
var didFinishPickingMediaWithInfo:((info:[String:AnyObject]) -> ())?
var didCancelPickingMedia:(() -> ())?
let imagePicker = UIImagePickerController()
override init() {
super.init()
// Set some defaults. These can be overriden by access the
// imagePicker member variable.
imagePicker.sourceType = .Camera
imagePicker.showsCameraControls = true
imagePicker.allowsEditing = true
imagePicker.mediaTypes = [kUTTypeImage as String]
imagePicker.delegate = self
}
func presentFromViewController(viewController:UIViewController) {
viewController.presentViewController(imagePicker, animated: true, completion: nil)
}
func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {
self.didFinishPickingMediaWithInfo?(info: info)
}
func imagePickerControllerDidCancel(picker: UIImagePickerController) {
self.didCancelPickingMedia?()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment