Hi,
Platforms state of the union shows the following code:
defer { await? log.close }
Note:
- I understand
awaitbutawait?seems new.
Questions
- Is
await?(question mark seems new) a new concept? What does it mean? - Or is the question mark a typo?
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"