Jim Jim - 6 months ago 8x
Swift Question

$T4 does not have a member named Generator ERROR swift

@IBAction func button(sender : AnyObject) {
var videoConnection : AVCaptureConnection!
videoConnection = nil
var connection : AVCaptureConnection
var port : AVCaptureInputPort
var stillImageOutput : AVCaptureStillImageOutput?

for connection in stillImageOutput?.connections{ //this line is where the error is



I am trying to take a picture with my custom camera and I am getting this error


stillImageOutput is an optional - even if you are using optional chaining, it cannot be used in a for loop, because if stillImageOutput is nil, the statement would be:

for connection in nil {

which wouldn't make sense.

To fix it, you have to use optional binding:

if let connections = x?.connections {
    for connection in connections {