skip to Main Content

How do I get the data returned from a combine publisher, to a view?

enter image description here

There are many examples of this that show sink -> print. There is nothing that clearly shows how to do anything other than print.

2

Answers


  1. Chosen as BEST ANSWER

    It turns out assign(to:) only works for publishers that return a single value, so you need to ignore the error one way or another. You can add .assertNoFailure() or replaceError(with:).

    I suppose if we wanted to handle the error, then we would need to put this into an object with a sink and then assign some local properties with the output.


  2. @State var text = ""
    var some View{
       Text(text)
        .padding()
        .onAppear(perform: {
            client.sink(receiveValue:{ value in 
            text = value
        }
      })
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search