DevPrep

All topics › Combine

Debounced search in Combine: debounce, removeDuplicates, switchToLatest

Middle PRO

The gist

Search-as-you-type is the canonical Combine task: turn a stream of keystrokes into a stream of up-to-date results. Each operator solves its own problem: debounce waits for a pause in typing, removeDuplicates drops a repeat of the same query, map turns a string into a network publisher, switchToLatest cancels the stale request, receive(on:) delivers the result on main.

The rest of this answer, with code and interview follow-ups, is in the DevPrep app.

Read the full answer in DevPrep

Practice this before your interview

DevPrep turns these answers into one-minute challenges: what does this code print, find the bug, mock interviews. One challenge a day.

Get DevPrep on the App Store