UIImage 类型的值没有成员 cgImageOrientation

Value of type UIImage has no member cgImageOrientation

我是 coreml 新手,我在读一本书时遇到了一个代码片段,当我尝试 运行 它时,我遇到了上述错误,我用谷歌搜索但没有成功, 这是我的代码

import UIKit
import Vision
extension UIImage {
    func detectFaces(completion:@escaping ([VNFaceObservation]?)->()){
        guard let image = self.cgImage else {
            completion(nil)
            return
        }
        let request = VNDetectFaceRectanglesRequest()
        DispatchQueue.global().async {
            let handler = VNImageRequestHandler(cgImage: image, orientation: self.cgImageOrientation)
            //above error here I think cgImageOrientation is no longer available but what's the solution anyways
        }
    }
}

这里我用的是swiftUI,生命周期方法也选为swiftui , 书名是orielly的《Practical Artificial intelligence with swift》

您需要继续学习本教程才能对其进行编译。本书的下一节将讨论创建 Views.swift,该节的第 8 步包括此扩展:

extension UIImage {
    func fixOrientation() -> UIImage? {
        UIGraphicsBeginImageContext(self.size)
        self.draw(at: .zero)
        let newImage = UIGraphicsGetImageFromCurrentImageContext()
        UIGraphicsEndImageContext()
        return newImage
    }

    var cgImageOrientation: CGImagePropertyOrientation {
        switch self.imageOrientation {
            case .up: return .up
            case .down: return .down
            case .left: return .left
            case .right: return .right
            case .upMirrored: return .upMirrored
            case .downMirrored: return .downMirrored
            case .leftMirrored: return .leftMirrored
            case .rightMirrored: return .rightMirrored
        }
    }
}