I'm learning Combine and how it can update a value using publishers. Currently I have created a variable that updates itself when validation fails.
var nameError: AnyPublisher<String, Never> {
$name
.dropFirst()
.debounce(for: 0.2, scheduler: RunLoop.main)
.removeDuplicates()
.map {
if $0.isEmpty || !self.isValidName() {
return "Name not valid"
}
return "Name"
}
.eraseToAnyPublisher()
}
I want to attach this to a Text() label so that it updates. Before Combine I would have an var error: String
that I would check against. But now I get the error Cannot convert value of type 'AnyPublisher<String, Never>' to expected argument type 'String'
How do I convert a var error: String
message to receive an AnyPublisher<String, Never>?