How to call url.lines?

I’m banging my head against a wall with this. Whatever I code I get - error: value of type 'URL' has no member 'lines' . This is not true - see lines. Can someone please enlighten me?

Which OS are you using?

Linux rantanplan 5.15.0-122-generic #132-Ubuntu SMP Thu Aug 29 13:45:52 UTC 2024 x86_64 x86_64 x\ 86_64 GNU/Linux

It’s probably missing from GitHub - swiftlang/swift-foundation: The Foundation project

From the docs:

On macOS, iOS, and other Apple platforms, apps should use the Foundation that comes with the operating system. The Foundation framework includes this code. On all other Swift platforms, swift-foundation is available as part of the toolchain. Simply import FoundationEssentials or import FoundationInternationalization to use its API. It is also re-exported from swift-corelibs-foundation's Foundation, FoundationXML, and FoundationNetworking modules.

I interpret this to mean that Foundation or swift-foundation already exists in my toolchain - I can also call it with import Foundation or more qualified with import struct Foundation.URL etc. - and I have already used it in other programs. Unfortunately, it also seems to be the case that the necessary imports are often simply omitted in the documentation on the assumption that this is obvious from the context or is clear to the reader anyway. Unfortunately, this is not always the case.

There are also many examples out there in the wild with the idiom url.lines - the authors are quite proud and rightly happy that this feature exists. I have not yet managed to get even one of them to work - unfortunately.

Foundation is present, but this type is not currently in the open source Foundation. If you want a workaround, you can find the implementation as of 2021 in this PR: Add AsyncBytes, AsyncLineSequence, AsyncCharacterSequence, and AsyncU… · swiftlang/swift-corelibs-foundation@4860800 · GitHub

It may require a little adapting to changes since then, e.g. the new signature of next() in AsyncSequence.

1 Like

Ah, OK. I will try this. I was already doubting my own sanity. Thanks. BTW, this idiom has of course worked in a playground :crazy_face::sunglasses: