await?

Hi,

Platforms state of the union shows the following code:

defer { await? log.close }

Note:

  • I understand await but await? seems new.

Questions

  1. Is await? (question mark seems new) a new concept? What does it mean?
  2. Or is the question mark a typo?
Answered by DTS Engineer in 890984022

I think that’s a typo.

Certainly, there’s nothing about await? in the Swift Evolution proposal for this much-requested feature, namely SE-0493 Support async calls in defer bodies.

Moreover, it’s not the only typo in that code. For example, it uses both fileName and filename.

Here’s a code snippet that compiles with Xcode 27 beta:

import Foundation

class FileHandle {
    init(_ fileName: String) { fatalError() }
    func write(_ data: Data) async throws { fatalError() }
    func close() async { fatalError() }
}

func exportData(at url: URL, to fileName: String) async throws {
    let log = FileHandle(fileName)

    defer { await log.close() }

    let (data, _) = try await URLSession.shared.data(from: url)
    try await log.write(data)
}

Share and Enjoy

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

Accepted Answer

I think that’s a typo.

Certainly, there’s nothing about await? in the Swift Evolution proposal for this much-requested feature, namely SE-0493 Support async calls in defer bodies.

Moreover, it’s not the only typo in that code. For example, it uses both fileName and filename.

Here’s a code snippet that compiles with Xcode 27 beta:

import Foundation

class FileHandle {
    init(_ fileName: String) { fatalError() }
    func write(_ data: Data) async throws { fatalError() }
    func close() async { fatalError() }
}

func exportData(at url: URL, to fileName: String) async throws {
    let log = FileHandle(fileName)

    defer { await log.close() }

    let (data, _) = try await URLSession.shared.data(from: url)
    try await log.write(data)
}

Share and Enjoy

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

Thank you so much @DTS Engineer Quinn!!

Thanks for the effort of pointing other typos and providing a working code, much appreciated!!

Little things trip me up, it would be nice for the presenters show code that actually compiles even if it is only featured for a few seconds.

Best to have a demo project to showcase these things.

I see you also asked this question on Swift Forums, and I’m glad that are answers were aligned (-:

Thanks for the effort of pointing other typos and providing a working code, much appreciated!!

You’re welcome.

But I should stress that my part of this is super easy. I just sit back, wait for Xcode 27 to get into beta, and then write the code in a largely functional Xcode and Swift. The folks working on this stuff don’t have that luxury.

Share and Enjoy

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

@DTS Engineer Quinn,

Hahah, that wasn't me, I wanted to post on swift.org but didn't, looks like others also spotted the same issue.

I can understand must such a rush with so much to do before WWDC

A big thanks from my end to the entire team who have done an amazing job!

await?
 
 
Q