Skip to content

Instantly share code, notes, and snippets.

@mohdsanadzakirizvi
Last active November 9, 2019 21:40
Show Gist options
  • Save mohdsanadzakirizvi/157fc13f48fe8ff134b7ec9a2e24bb41 to your computer and use it in GitHub Desktop.
Save mohdsanadzakirizvi/157fc13f48fe8ff134b7ec9a2e24bb41 to your computer and use it in GitHub Desktop.
import CoreML
import Vision
import UIKit
class ViewController: UIViewController {
// MARK: - IBOutlets
@IBOutlet weak var scene: UIImageView!
@IBOutlet weak var answerLabel: UILabel!
// MARK: - View Life Cycle
override func viewDidLoad() {
super.viewDidLoad()
guard let image = UIImage(named: "scenery") else {
fatalError("no starting image")
}
scene.image = image
}
}
// MARK: - IBActions
extension ViewController {
@IBAction func pickImage(_ sender: Any) {
let pickerController = UIImagePickerController()
pickerController.delegate = self
pickerController.sourceType = .savedPhotosAlbum
present(pickerController, animated: true)
}
}
// MARK: - UIImagePickerControllerDelegate
extension ViewController: UIImagePickerControllerDelegate {
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
dismiss(animated: true)
guard let image = info[UIImagePickerControllerOriginalImage] as? UIImage else {
fatalError("couldn't load image from Photos")
}
scene.image = image
}
}
// MARK: - UINavigationControllerDelegate
extension ViewController: UINavigationControllerDelegate {
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment