I use AVFoundation in swift for shooting, but I cannot convert any functional lines of code from objective c to Swift. My function code:
- (void) capImage { //method to capture image from AVCaptureSession video feed AVCaptureConnection *videoConnection = nil; for (AVCaptureConnection *connection in stillImageOutput.connections) { for (AVCaptureInputPort *port in [connection inputPorts]) { if ([[port mediaType] isEqual:AVMediaTypeVideo] ) { videoConnection = connection; break; } } if (videoConnection) { break; } } NSLog(@"about to request a capture from: %@", stillImageOutput); [stillImageOutput captureStillImageAsynchronouslyFromConnection:videoConnection completionHandler: ^(CMSampleBufferRef imageSampleBuffer, NSError *error) { if (imageSampleBuffer != NULL) { NSData *imageData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageSampleBuffer]; [self processImage:[UIImage imageWithData:imageData]]; } }];
}
This line sends me an error. AnyObject [] does not match the sequencfe .. protocol:
for (AVCaptureInputPort *port in [connection inputPorts]) {
In quick:
for port:AnyObject in connection.inputPorts {
And I do not know how to convert this string:
[stillImageOutput captureStillImageAsynchronouslyFromConnection:videoConnection completionHandler: ^(CMSampleBufferRef imageSampleBuffer, NSError *error) {
Can anyone help me convert to fast? Thanks!!
source share