I have a textfield and I need that when I write smth. in textfield it sends request to server without clicking at any button. For example if my sending text is the same as server's text it print that text. I am using SwiftUI and Combine. Below is my code.
@State var cancellable: AnyCancellable?
.onReceive(Just($homePageVM.orderNumber)) { res in
if !homePageVM.orderNumber.isEmpty {
cancellable = homePageVM.orderNumber
.publisher
.receive(on: RunLoop.main)
.sink(receiveCompletion: { completion in
print(completion)
}, receiveValue: { value in
homePageVM.getVoucherInfo { result in
if homePageVM.orderNumber == homePageVM.getVoucherInfoModel?.orderNumber {
print(result)
}
}
})
}
}
I am using onreceive because I need to send the data every time i change the text. But in the result i receive an unended cycle. How can i send data only one time every time I change my text? Please help me.