Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS

How to get image preview from actual NSCamera to be displayed on own main.storyboard view controller ??

I trying to get the image from NSCamera onto my own view controller after photo button is pressed, instead of it still being displayed on the camera operator. I have got the code for camera to appear and can take the photo but after being taken, when I press 'Use Photo' it tries to go to my view controller but backs out and goes back to camera (with a issue occurring on Xcode saying 'Reading from public effective user settings' ?? not sure if this is to do with my photoLibrary info.plist but not sure what to do.

Here is my code at the moment:

class ViewController: UIViewController, UINavigationControllerDelegate, UIImagePickerControllerDelegate { let imagePicker = UIImagePickerController() @IBOutlet weak var imageViewer: UIImageView! @IBOutlet weak var photoPreview: UIImageView!

override func viewDidAppear(_ animated: Bool) {

    if UIImagePickerController.isCameraDeviceAvailable( UIImagePickerControllerCameraDevice.front) {
        imagePicker.delegate = self
        imagePicker.sourceType = UIImagePickerControllerSourceType.camera
        present(imagePicker, animated: true, completion: nil)
    }

}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

func imagePickerController(picker: UIImagePickerController, didFinishPickingImage image: UIImage!, editingInfo: [NSObject : AnyObject]!) {
    dismiss(animated: true, completion: nil)
    imageViewer.image = image
}

}