App is crashing when using "withCheckedContinuation" in Xcode 15 beta 5

We are experiencing an issue with withCheckedContinuation in our Swift project. Our implementation was working perfectly in a previous version of Xcode and continues to work in the simulator. However, it fails to work on a real device. Here’s a brief description of the problem:

•	Environment:
- Xcode Version: Xcode 16.0 Beta 5
- Swift Version: Swift 5
- OS: IOS18 beta 5

•	Problem:
    The code using withCheckedContinuation behaves as expected in the simulator but fails on a physical device. We are receiving a “bad access to memory” error when running on a real device.

•	What We’ve Tried:
1. Verified that the code works in previous Xcode versions.
2. Tested on different simulators, where it runs without issues.
3. Checked for any obvious errors in memory handling or threading.

Code Example: Here’s a simplified version of the problematic code:

    var body: some View {
        VStack {
            Text("Hello, world!")
        }
        .padding()
        .onAppear {
            Task {
                await self.checkTrialOrIntroductoryDiscountEligibilityAsync()
            }
        }
    }
    
    func checkTrialOrIntroductoryDiscountEligibilityAsync() async {
        return await withCheckedContinuation { continuation in
            checkTrialOrIntroDiscountEligibility() {
                continuation.resume()
            }
        }
    }

    func checkTrialOrIntroDiscountEligibility(completion: () -> Void) {
        completion()
    }
}
Answered by DTS Engineer in 804111022

Folks, thanks for sharing the latest info. And please do update this thread if you see this crash on the released iOS 18.0 or later.

Share and Enjoy

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

We are seeing this issue as well, happening on builds from Xcode 16 and users on iOS 18. However, we have not reproduced it on the 16 Pro running iOS 18

We are continuing to see a greatly increased number of crashes for withCheckedContinuation and XCode16/iOS18

Seems that people are having to switch to "withUnsafeThrowingContinuation" to avoid this crash:

https://github.com/swiftlang/swift/pull/76218#issuecomment-2375423832

App is crashing when using "withCheckedContinuation" in Xcode 15 beta 5
 
 
Q