Accessing AVCaptureVideoPreviewLayer.connection always crashes

Originator:Virtuosity0021
Number:rdar://27759566 Date Originated:08-Aug-2016 09:19 PM
Status:Open Resolved:
Product:iOS SDK Product Version:10.0
Classification:Crash/Hang/Data Loss Reproducible:Always
 
Summary:
When accessing the `connection` instance property on an `AVCaptureVideoPreviewLayer` instance, the app will always crash. Accessing other instance properties succeeds.

Steps to Reproduce:
1. Create an instance of AVCaptureVideoPreviewLayer
2. Attempt to access the connection property on the new instance (by any method to unwrap the optional)
3. Attempt to load onto your iOS 10 beta device
4. Notice how it throws a fatal error and aborts the app while trying to access that property:

```
fatal error: unexpectedly found nil while unwrapping an Optional value
```

Expected Results:
I expect to either access the property or to skip it via unwrapping.

Actual Results:
Regardless of unwrapping or not, the app aborts and throws a fatal error.

Version:
10.0 (14A5322e)

Notes:
Example code:

```
previewLayer = AVCaptureVideoPreviewLayer(session: CameraManager.captureSession) as AVCaptureVideoPreviewLayer

previewLayer?.connection.videoOrientation = AVCaptureVideoOrientation.LandscapeRight
previewLayer?.frame = imageView.bounds
previewLayer?.videoGravity = AVLayerVideoGravityResizeAspectFill
previewLayer?.mask = maskLayer

imageView.layer.addSublayer(previewLayer!)

dispatch_async(CameraManager.sessionQueue) { () -> Void in
  CameraManager.captureSession.startRunning()
}
```

Configuration:
iPhone 6 128gb

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!