App is crashing when using "withCheckedContinuation" in Xcode 16 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 Dixit7405 in 803376022

This is fixed in the latest Xcode 16 beta 6 and later.

Same here. I release new version last week. Super increases crash on withCheckedThrowingContinuation.

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

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