AVAudioSession.setCategory(_:) is incorrectly unavailable in Swift 4.2 for iOS 9 and older

Number:rdar://45397675 Date Originated:October 19 2018
Status:Duplicate of 42023905 Resolved:Open
Product:iOS + SDK (AVFoundation) Product Version:
Classification: Reproducible:Always
The prime example of AVAudioSession documentation was broken with Swift 4.2: https://developer.apple.com/documentation/avfoundation/avaudiosession

What is happening is that the `setCategory(_:)` function was incorrectly marked as unavailable in Swift 4.2, making it impossible to set AVAudioSession category on iOS 9 and older using Swift 4.2.

Steps to Reproduce:
1. Make a Swift project for iOS 9 (or older)
2. Try to build with Xcode 10.0 or Xcode 10.1 Beta 3 using Swift 4.2:

import AVFoundation;
let foo: Void = {
    if #available(iOS 10.0, *) {
        _ = try? AVAudioSession.sharedInstance().setCategory(.playback, mode: .default, options: [])
    } else {
        // Required for iOS 9 and older
        // Works in Swift 4.1 and in Objective-C, but not in Swift 4.2
        _ = try? AVAudioSession.sharedInstance().setCategory(.playback)

Expected Results:
It should build without warnings. AVAudioSession.setCategory(_:) should be available in Swift 4.2 for iOS 9 and older the same way as it's available with its Objective-C counterpart `setCategory:error:` (https://developer.apple.com/documentation/avfoundation/avaudiosession/1616583-setcategory) 

Actual Results:
Starting with Swift 4.2, we get the error "'setCategory' is unavailable in Swift". This problem is also mentioned at https://forums.swift.org/t/using-methods-marked-unavailable-in-swift-4-2/14949.

StackOverflow thread on the matter (https://stackoverflow.com/questions/52413107/avaudiosession-setcategory-availability-in-swift-4-2) has suggested two working workarounds for setCategory unavailability:
* Use Swift 4.1 instead of Swift 4.2  (-_-')
* Use Objective-C instead of Swift 4.2 (-_-'')

Xcode 10.0 + Swift + iOS 9
Xcode 10.1 beta 3 + Swift + iOS 9


Fixed in Xcode 10.2.

By adigitalknight at April 16, 2019, 1:42 a.m. (reply...)

Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!