AVFoundation in XCode 12 Beta 3

I have a macOS app which uses AVFoundation that was building fine with XCode 12 Beta 2. In Beta 3, I get:

Code Block
Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.0.sdk/usr/lib/swift/AVFoundation.swiftmodule/x86_64-apple-macos.swiftinterface:72:11: 'AVAudioSession' is unavailable in macOS
/AVFoundation.AVAudioSession:2:12: 'AVAudioSession' has been explicitly marked unavailable here


Code Block
Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.0.sdk/usr/lib/swift/AVFoundation.swiftmodule/x86_64-apple-macos.swiftinterface:129:11: 'AVAudioSession' is unavailable in macOS
/AVFoundation.AVAudioSession:2:12: 'AVAudioSession' has been explicitly marked unavailable here


Code Block
Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.0.sdk/usr/lib/swift/AVFoundation.swiftmodule/x86_64-apple-macos.swiftinterface:1:1: Failed to build module 'AVFoundation' from its module interface; the compiler that produced it, 'Apple Swift version 5.3 (swiftlang-1200.2.22.2 clang-1200.0.25.1)', may have used features that aren't supported by this compiler, 'Apple Swift version 5.3 (swiftlang-1200.0.22.4 clang-1200.0.25.1)'

I didn't see anything about this in the known issues of Beta 3. Does anyone have any thoughts on what's going on?

Answered by Gerrit in 623184022
I hit the same error and out of curiosity I created a new empty project, and discovered that it failed to build as soon as I added "import AVFoundation" to any source file... so it looks like a bug in the macOS SDK.

I looked at the .swiftinterface file for AVFoundation (for my build platform it was 'AVFoundation.swiftmodule/x86_64-apple-macos.swiftinterface') and the problem seems to be that 'extension AVAudioSession.Location' is not explicitly marked as unavailable on macOS. Because it's an extension to AVAudioSession and AVAudioSession is marked as unavailable it won't compile.

So I added '@available(OSX, unavailable)' in two different places where the extension to AVAudioSession is defined. So where it looked like this:

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


I changed it to this:

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


That got everything compiling and working again.
Accepted Answer
I hit the same error and out of curiosity I created a new empty project, and discovered that it failed to build as soon as I added "import AVFoundation" to any source file... so it looks like a bug in the macOS SDK.

I looked at the .swiftinterface file for AVFoundation (for my build platform it was 'AVFoundation.swiftmodule/x86_64-apple-macos.swiftinterface') and the problem seems to be that 'extension AVAudioSession.Location' is not explicitly marked as unavailable on macOS. Because it's an extension to AVAudioSession and AVAudioSession is marked as unavailable it won't compile.

So I added '@available(OSX, unavailable)' in two different places where the extension to AVAudioSession is defined. So where it looked like this:

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


I changed it to this:

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


That got everything compiling and working again.
12
Please don't forget to file a bug report.
Thanks, this worked like a charm. Sent feedback so a bug can be opened
Gerrit how did you edit the file? Xcode is not letting me, and I cannot find the location
Thanks, this works! I close Xcode and changed as you suggested and reopen project.
Thanks Gerrit! Here's a bit more detail for anyone having trouble finding and editing this file.

Assuming your Xcode beta 3 is located at /Applications/Xcode-beta.app this file is located at:

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


I added @available(OSX, unavailable) to lines 71 and 129 of this file.
Looks like it's been fixed in Beta 4. So that doesn't solve my problem with the simulator. But it's been added in Beta 4
AVFoundation in XCode 12 Beta 3
 
 
Q