我遇到了一个问题,Xcode13b2( Swift 15SDK)更改了AVCapturePhoto.previewCGImageRepresentation()的iOS返回类型。在Xcode12.5.1 (iOS 14SDK)中,此方法返回Unmanged<CGImage>。在13b2 - 13b4中,它返回CGImage?。
我需要我的代码在两个Xcode版本下编译,因为Xcode13还有其他问题,不能用来向App Store提交构建。我认为我写这篇文章很聪明,但它不会编译,因为它不是条件代码编译检查,而是运行时检查:
extension AVCapturePhoto {
func stupidOSChangePreviewCGImageRepresentation() -> CGImage? {
if #available(iOS 15, *) {
return self.previewCGImageRepresentation()
} else {
return self.previewCGImageRepresentation()?.takeUnretainedValue()
}
}
}另一种可能是创建用户定义的Xcode设置,但我认为这不能基于Xcode或SDK版本有条件地完成。
可能有一些不安全的指针装腔作势,人们可以做…
还有其他想法吗?
发布于 2021-08-17 20:26:07
你可以检查一下swift编译器的版本。在撰写本文时,维基百科上提供了一个详尽的列表。
https://en.wikipedia.org/wiki/Xcode#Toolchain_versions
extension AVCapturePhoto {
func stupidOSChangePreviewCGImageRepresentation() -> CGImage? {
#if compiler(>=5.5)
return self.previewCGImageRepresentation()
#else
return self.previewCGImageRepresentation()?.takeUnretainedValue()
#endif
}
}https://stackoverflow.com/questions/68644502
复制相似问题