0

When accessing the camera and trying to capture a still, I get an error adding the output settings. It says that I can't add a nil to AVCaptureOutput

Here's the code:

var imageCaptured : AVCaptureStillImageOutput?

let outputSettings:Dictionary = [AVVideoCodecJPEG:AVVideoCodecKey]
imageCaptured?.outputSettings = outputSettings
captureSession.addOutput(imageCaptured) //error here

This is the error:

* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '* Can't add a nil AVCaptureOutput'

AppDever
  • 687
  • 1
  • 7
  • 17

1 Answers1

1

You aren't setting imageCaptured to anything. It's nil.

For example how to initialize it, see How To Use AVCaptureStillImageOutput To Take Picture.

Community
  • 1
  • 1
Mike Taverne
  • 9,156
  • 2
  • 42
  • 58
  • I'm not setting it to the Codecs in the Dictionary? Your link is Objective-C... My code above is what I've tried to convert from Obj-C to Swift – AppDever Dec 04 '14 at 04:06
  • 1
    Correct, you are not setting it, or it would not be nil. You have declared it to be a var of type AVCaptureStillImageOutput? but have not assigned anything to it. – Mike Taverne Dec 04 '14 at 04:28
  • Doh! I was missing imageCaptured = AVCaptureStillImageOutput() – AppDever Dec 04 '14 at 14:15