Value of type 'AVCapturePhotoSettings' has no member 'availablePreviewPhotoPixelFormatTypes
Asked Answered
B

3

10
@objc func launchCoreML() {
    let settings = AVCapturePhotoSettings()
    let previewPixelType = settings.availablePreviewPhotoPixelFormatTypes.first
    let previewFormat = [
        kCVPixelBufferPixelFormatTypeKey as String: previewPixelType, 
        kCVPixelBufferWidthKey as String: 160, 
        kCVPixelBufferHeightKey as String: 160
    ] as [String : Any]

    settings.previewPhotoFormat = previewFormat
    cameraOutput.capturePhoto(with: settings, delegate: self)
}

I have an error saying:

Value of type 'AVCapturePhotoSettings' has no member 'availablePreviewPhotoPixelFormat'.

I'm using the beta version of Xcode 9.

Brundisium answered 8/8, 2017 at 6:32 Comment(0)
E
13

In beta 4 this got renamed to __availablePreviewPhotoPixelFormat. I haven't looked at beta 5 yet.

End answered 8/8, 2017 at 8:25 Comment(5)
Still __availablePreviewPhotoPixelFormatTypes in beta 5.Usn
I am struggling to find same in beta 5 aswell.Infarction
This is happening in Xcode 9 GM as well. Thank you so much.Conveyancer
Using Xcode Version 9.0 (9A235) -- cannot solve this issue (Emetic
right answer should be the one from @eharo2. "__availablePreviewPhotoPixelFormatTypes"Shotgun
S
5

I experienced the same problem after upgrading to Xcode 12.0

It seems that settings.availablePreviewPhotoPixelFormatTypes has been changed to settings.__availablePreviewPhotoPixelFormatTypes again in the Final Xcode Release: Version 12.0 (12A7209). I have been using it without the 'rename' for at least 2 years. Thx to @Matthijs Hollemans for the help

EDIT: This is the official response with regards to this change: https://developer.apple.com/forums/thread/86810?answerId=259270022#259270022

This code compiles OK.

let settings = AVCapturePhotoSettings()
guard let previewPixelType = settings.__availablePreviewPhotoPixelFormatTypes.first else { return }
let previewFormat = [
    kCVPixelBufferPixelFormatTypeKey as String: previewPixelType,
    kCVPixelBufferWidthKey as String: 160,
    kCVPixelBufferHeightKey as String: 160
]
settings.previewPhotoFormat = previewFormat
output.capturePhoto(with: settings, delegate: self)
Stockjobber answered 23/9, 2020 at 15:28 Comment(0)
M
1
        var photoSettings: AVCapturePhotoSettings
        if #available(iOS 11.0, *) {
            photoSettings = AVCapturePhotoSettings.init(format: [AVVideoCodecKey: AVVideoCodecType.jpeg])
        } else {
            // Fallback on earlier versions
            photoSettings = AVCapturePhotoSettings()
            if photoSettings.__availablePreviewPhotoPixelFormatTypes.count > 0 {
                photoSettings.previewPhotoFormat = [kCVPixelBufferPixelFormatTypeKey as String : photoSettings.__availablePreviewPhotoPixelFormatTypes.first!]
            }
        }
Marna answered 9/10, 2017 at 7:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.