I want to use a @State
variable both for the UI and for computing a value.
For example, let's say I have a TextField
bound to @State var userInputURL: String = "https://"
. How would I take that userInputURL
and connect it to a publisher so I can map
it into a URL
.
Pseudo code:
$userInputURL.publisher()
.compactMap({ URL(string: $0) })
.flatMap({ URLSession(configuration: .ephemeral).dataTaskPublisher(for: $0).assertNoFailure() })
.eraseToAnyPublisher()