Thanks for being a part of WWDC25!

How did we do? We’d love to know your thoughts on this year’s conference. Take the survey here

Swift Testing deinit not supporting async

Why doesn’t deinit support async? At the end of a test, I want to wipe data from HealthKit, and it’s delete function is asynchronous.

Answered by DTS Engineer in 795379022
Why doesn’t deinit support async?

Asynchronous deinitialers are an ongoing topic of conversation on Swift Evolution. The specific proposal was SE-0371 Isolated synchronous deinit, and you can follow links from there to the various discussion threads.

Depending on your specific goals, there may be ways around this. One option is to kick off a new task to do the clean up, and then not wait for it before returning from your deinitialiser.

Share and Enjoy

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

Accepted Answer
Why doesn’t deinit support async?

Asynchronous deinitialers are an ongoing topic of conversation on Swift Evolution. The specific proposal was SE-0371 Isolated synchronous deinit, and you can follow links from there to the various discussion threads.

Depending on your specific goals, there may be ways around this. One option is to kick off a new task to do the clean up, and then not wait for it before returning from your deinitialiser.

Share and Enjoy

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

It’s better to reply as a reply, rather than in the comments; see Quinn’s Top Ten DevForums Tips for this and other titbits.

I don't see how it helps the situation of cleaning up with an asynchronous function.

OK. If you post a specific example, I’d be happy to take a look.

Share and Enjoy

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

Swift Testing deinit not supporting async
 
 
Q