In the "Platforms State of the Union" video of WWDC2021 at 28:00 it was mentioned that
[Apple] even added support for asynchronously iterating line-by-line through a file
in Foundation for macOS 12/iOS 15 and Swift 5.5.
What is that new API, how can I now asynchronously iterate line-by-line through a file?
The main thing they added that enables this, is
AsyncSequence.AsyncSequenceis likeSequence, but itsIterator.nextmethod isasync throws.Specifically, you can use
URLSession.AsyncBytes.linesto get anAsyncSequenceof the lines in a file.Suppose you are in an
async throwsmethod, you can do:Note that there is also
FileHandle.AsyncBytes.lines, but in the documentation it says: