$ 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

+3


source to share


2 answers


stillImageOutput

is optional - even if you are using optional chaining, it cannot be used in a loop for

, because if it stillImageOutput

is nil, the statement will look like this:

for connection in nil {
}

      

which wouldn't make sense.



To fix this, you have to use an optional binding:

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

    }
}

      

+10


source


Just complementing Antonio's answer, if you are 100% sure that in a certain part of the code your optional is not nil

, you can simply use it !

directly in yours var

to avoid checking if let

.



for connection in stillImageOutput!.connections {

}

      

0


source







All Articles