FullScreenCamera icon indicating copy to clipboard operation
FullScreenCamera copied to clipboard

Value of type '[AVCaptureDevice]' has no member 'compactMap'

Open nirav-kotecha opened this issue 6 years ago • 7 comments

let cameras = session.devices.compactMap { $0 } - error on this line

screen shot 2018-04-12 at 11 36 09 am

nirav-kotecha avatar Apr 12 '18 06:04 nirav-kotecha

Updated to Swift 4.1, error is gone but getting cameras as anempty array.

Jane930525 avatar Apr 18 '18 06:04 Jane930525

Try to replace:

let session = AVCaptureDevice.DiscoverySession(deviceTypes: [.builtInDualCamera], mediaType: AVMediaType.video, position: .unspecified)

By:

let session = AVCaptureDevice.DiscoverySession(deviceTypes: [.builtInWideAngleCamera], mediaType: AVMediaType.video, position: .unspecified)

vermotr avatar May 03 '18 10:05 vermotr

Still getting the same error...

sri1sri avatar May 26 '18 07:05 sri1sri

Could someone one please help... THANKYOU in advance..

sri1sri avatar May 26 '18 07:05 sri1sri

Try to use something like this. let cameras = (sessions.devices.flatMap { $0 })

raza08 avatar Jun 04 '18 08:06 raza08

@sri1sri generic instance method compactMap seems to be supported from iOS 7.0+ and compatible with Xcode 9.3+ . What is the SDK version you are targeting and Xcode version you are using ?

erkandiken avatar Jun 04 '18 10:06 erkandiken

Still getting the same error...

  1. Use as? [AVCaptureDevice] at the end of .compact { $0 }

  2. ` let session = AVCaptureDevice.DiscoverySession(deviceTypes: [.builtInWideAngleCamera], mediaType: AVMediaType.video, position: .unspecified)

         let cameras = session.devices.compactMap { $0 }
         guard !cameras.isEmpty else { throw CameraControllerError.noCamerasAvailable }`
    

GodsEye-07 avatar Jan 20 '20 12:01 GodsEye-07