How to successfully import AVFoundation using Swift in Xcode 12 beta 3?

Viewed 495

With Xcode 12 beta 3 calling:

import AVFoundation

in a Swift file causes the build to fail. The error text includes:

Failed to build module 'AVFoundation' from its module interface; the compiler that produced it, [...], may have used features that aren't supported by this compiler.

Is there a workaround? (reformulating as Q&A on SO to aid other developers on this beta)

1 Answers

extension AVAudioSession.Location needs to be marked as unavailable for macOS.

Edit the relevant .swift-interface file. When installed in /Applications, this file should be found at:

/Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/lib/swift/AVFoundation.swiftmodule/x86_64-apple-macos.swiftinterface

There are 2 locations to change from:

@available(iOS 7.0, watchOS 2.0, tvOS 9.0, *)
extension AVAudioSession.Location {

to:

@available(OSX, unavailable)
@available(iOS 7.0, watchOS 2.0, tvOS 9.0, *)
extension AVAudioSession.Location {

Many thanks to users eldevo (Question) and Gerrit (Answer) on the Apple Developer Forums, see https://developer.apple.com/forums/thread/655334

Related