Combine is Apple's reactive framework for handling streams of values over time (text input, timers, network results). SwiftUI uses it under the hood.
A publisher/subscriber
import Combine
class SearchModel: ObservableObject {
@Published var query = ""
@Published var results: [String] = []
private var bag = Set<AnyCancellable>()
init() {
$query
.debounce(for: .milliseconds(300), scheduler: RunLoop.main)
.removeDuplicates()
.sink { [weak self] q in self?.search(q) }
.store(in: &bag)
}
func search(_ q: String) { /* ... */ }
}
debounce waits until the user stops typing — a classic search pattern.
Tip: For most new code, async/await covers your needs; reach for Combine when you need value streams and operators like debounce.
Summary
Combine models values that change over time. @Published is a Combine publisher; operators like debounce/removeDuplicates shape the stream.