Apple Swift 3&Xcode 9 GM的Mach-O Linker(ld)错误组

这是运行良好,直到通用Xcode(和iOS 11)。 现在我得到这些错误:

Apple Mach-O Linker (ld) Error Group "__T0So20AVCapturePhotoOutputC12AVFoundation01_abC16SwiftNativeTypesACWP", referenced from: xxxxxxxxxx "__T012AVFoundation37_AVCapturePhotoOutputSwiftNativeTypesPAAE012availableRawc11PixelFormatG0SaySo8NSNumberCGfg", referenced from: xxxxxxxxx " "__T0So22AVCapturePhotoSettingsC12AVFoundation01_abC16SwiftNativeTypesACWP", referenced from: xxxxxxxxxx ld: symbol(s) not found for architecture arm64 clang: error: linker command failed with exit code 1 (use -v to see invocation) 

它指向的一些行是:

 photoSettings = AVCapturePhotoSettings(rawPixelFormatType: OSType(self.photoOutput.availableRawPhotoPixelFormatTypes.first!)) photoSettings.previewPhotoFormat = [kCVPixelBufferPixelFormatTypeKey as String: photoSettings.availablePreviewPhotoPixelFormatTypes.first!.uint32Value, kCVPixelBufferWidthKey as String: 3024, kCVPixelBufferHeightKey as String: 3024] 

也:

 let rawFormat = self.photoOutput.availableRawPhotoPixelFormatTypes.first!.uint32Value photoSettings = AVCapturePhotoSettings(rawPixelFormatType: OSType(rawFormat), processedFormat: [AVVideoCodecKey : AVVideoCodecJPEG, AVVideoCompressionPropertiesKey : [AVVideoQualityKey : 1.0]] as [String : Any]) photoSettings.previewPhotoFormat = [kCVPixelBufferPixelFormatTypeKey as String: photoSettings.availablePreviewPhotoPixelFormatTypes.first!.uint32Value, kCVPixelBufferWidthKey as String: 3024, kCVPixelBufferHeightKey as String: 3024] 

2017年9月15日更新:

苹果官方回应:

我们的歉意。 对于使用Swift 3.2或Swift 4.0的应用程序,几个AVFoundation捕获API(外部协议上的公共扩展)在Xcode 9中被无意中标记为私有。以下AVFoundation API暂时不可用:

  • AVCaptureDevice.Format.supportedColorSpaces

  • AVCaptureDevice.supportedFlashModes

  • AVCapturePhotoOutput.availablePhotoPixelFormatTypes

  • AVCapturePhotoOutput.availableRawPhotoPixelFormatTypes

  • AVCapturePhotoSettings.availablePreviewPhotoPixelFormatTypes

    作为解决方法,您可以通过在每个API之前加双下划线( __ )来使用这些API的SwiftPrivate版本。 例如,将AVCaptureDevice.Format.supportedColorSpaces更改为AVCaptureDevice.Format.__supportedColorSpaces

我可以确认使用__availablePreviewPhotoPixelFormatTypes修复了构build错误。

例如

 let settings = AVCapturePhotoSettings() let previewPixelType = settings.__availablePreviewPhotoPixelFormatTypes.first! 

来源: https : //forums.developer.apple.com/thread/86810#259270

这个错误出现在Xcode 9( rdar://33903950 )的早期testing版本中,显然已经解决了(见这个问题 )。 它在GM的构build中也回馈给我。 我正在提交有关此问题的rdar ://34412264 。 希望很快得到解决,而另一个通用汽车的build设是相关的。 在此之前,我可以继续使用较早版本的Xcode 9,但无法发布该工作。 这是我的应用程序的总展示塞。

编辑:我还会提到有关AVCapturePhotoSettings的预览属性( previewPhotoFormatkCVPixelBufferPixelFormatTypeKeykCVPixelBufferWidthKey等)的注释行允许您的项目build立。 如果你可能在你的项目中忽略这些,这可能是一个很好的解决方法。

我改变了:

 if cameraOutput.supportedFlashModes.contains(NSNumber(value: flashMode.rawValue)) { 

至:

 if cameraOutput.__supportedFlashModes.contains(NSNumber(value: flashMode.rawValue)) { 

 let previewPixelType = settings.availablePreviewPhotoPixelFormatTypes.first! 

 let previewPixelType = settings.__availablePreviewPhotoPixelFormatTypes.first! 

和应用程序启动。