The async/await API crashes in Xcode 16.3 and later

We use several UIKit and AVFoundation APIs in our project, including:

Moreover, we use the Swift Concurrency versions for these APIs:

@MainActor
func setAlternateIconName(_ alternateIconName: String?) async throws
var allTasks: [URLSessionTask] { get async }
func loadMediaSelectionGroup(for mediaCharacteristic: AVMediaCharacteristic) async throws -> AVMediaSelectionGroup?

Everything worked well with these APIs in Xcode 16.2 and earlier, but starting from Xcode 16.3 (and in 16.4), they cause crashes. We've rewritten the APIs to use completion blocks instead of async/await, and this approach works.

Stack traces:

Also, I attached some screenshots from Xcode 16.4.

Answered by DTS Engineer in 846383022

You’ve described three different failures, but each of them in limited detail. I’d like to focus on one case and then dig deeper into that case. Because I’m a Networking Guy™, I chose your second case (-:

Here’s what I did:

  1. On macOS 15.5, using Xcode 16.4, I created a new project from the iOS > App template.

  2. I added this code to the main view:

    Button("Test") {
        Task {
            print(await URLSession.shared.allTasks)
        }
    }
    
  3. I built and ran it on the iOS 18.5 simulator, and then clicked the button. It didn’t crash.

  4. I built and ran it on the iOS 18.5 device, and then tapped the button. It didn’t crash.

I’m not sure why it’s crashing for you. I recommend that you repeat the above process. That’ll tell us whether you have an environmental issue, or it’s something specific to your main project.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Interesting. We use UIApplication.shared.setAlternateIconName() in the same way as you describe: the async/await version in a @MainActor annotated method. And we have no problem, neither in Xcode 16.3 nor 16.4. Both simulator and physical device.

You’ve described three different failures, but each of them in limited detail. I’d like to focus on one case and then dig deeper into that case. Because I’m a Networking Guy™, I chose your second case (-:

Here’s what I did:

  1. On macOS 15.5, using Xcode 16.4, I created a new project from the iOS > App template.

  2. I added this code to the main view:

    Button("Test") {
        Task {
            print(await URLSession.shared.allTasks)
        }
    }
    
  3. I built and ran it on the iOS 18.5 simulator, and then clicked the button. It didn’t crash.

  4. I built and ran it on the iOS 18.5 device, and then tapped the button. It didn’t crash.

I’m not sure why it’s crashing for you. I recommend that you repeat the above process. That’ll tell us whether you have an environmental issue, or it’s something specific to your main project.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

@DTS Engineer thank you for your prompt response 🙏

I have macOS 15.5 and Xcode 16.4. I repeated your steps:

  • Created a new project;
  • Implemented the same button with the same action.

Everything works fine. Moreover, all of the APIs listed above work well in other projects.

It’s definitely something specific to my project. Unfortunately, I have no idea what’s causing the issue or what I need to do next.

Thanks for running that test. This is a weird one.

But I do have a new test for you:

  1. Make sure your project is checked into your version control system. You’ll want to revert your entire source base when you’re done with this test.

  2. Open the project in Xcode and remove all the source code and libraries.

  3. Add in the source code from the test project everything works.

  4. Run it and tap the Test button.

The goal of this is to isolate build settings problems from source code problems. If the test code crashes, it’s likely a build settings issue. However, if the test code works, then your build settings are fine and there’s something about the code you deleted that’s triggering this.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

@DTS Engineer

Ok, I followed your steps and discovered something interesting 🤓

Since my project is quite large, I initially decided to move and run the test code directly in the AppDelegate’s application(_:didFinishLaunchingWithOptions:) method. And it works! Even the UIApplication.shared.setAlternateIconName() method works as well.

final class AppDelegate: UIResponder, UIApplicationDelegate {

    func application(
        _ application: UIApplication,
        didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
    ) -> Bool {
        Task {
            _ = try! await URLSession.shared.allTasks
            try! await UIApplication.shared.setAlternateIconName(...)
        }
    }
}

Another unexplained curious thing I noticed is that after making these API calls in AppDelegate, my original code starts to work 😳

I'll provide some more information about my project, in case it helps. My project uses a modular architecture, and I use Tuist to generate the .xcodeproj and .xcworkspace files. The code that's causing the crash is located in a SwiftPM package. Additionally, the allTasks code is in one package, while setAlternateIconName() is in another. Tuist generates subprojects with statically linked frameworks from these SwiftPM packages.

The async/await API crashes in Xcode 16.3 and later
 
 
Q