I am coding iOS app with Swift 5+ . I need to download a file from http url and read it line by line. The file can be big. I do not want to save it locally to temp place to read later. Also, i do not want to load full file to memory.
I found there is support of URLSession with delegate functions. Here i can receive portions of a file data during download. But also this approach returns full contents of the file in the end of the process.
I am using the approach described here https://developer.apple.com/documentation/foundation/url_loading_system/fetching_website_data_into_memory
I have 2 problems:
- Full file is still returned in response argument of the task callback
- How to make lines from Data() type? bytes are appended to the receivedData variable. How to get string lines from it? How to read bytes till "\n" and convert them to a string?