Skip to content

Instantly share code, notes, and snippets.

@rmirabelli
Created December 17, 2021 19:54
Show Gist options
  • Save rmirabelli/8af78d509d1deba87a4a638a315cdfa8 to your computer and use it in GitHub Desktop.
Save rmirabelli/8af78d509d1deba87a4a638a315cdfa8 to your computer and use it in GitHub Desktop.
A sample from Apple's Documentation for Pub/Sub in Comine
let sub = NotificationCenter.default
.publisher(for: NSControl.textDidChangeNotification, object: filterField)
.map( { ($0.object as! NSTextField).stringValue } )
.filter( { $0.unicodeScalars.allSatisfy({CharacterSet.alphanumerics.contains($0)}) } )
.debounce(for: .milliseconds(500), scheduler: RunLoop.main)
.receive(on: RunLoop.main)
.assign(to:\MyViewModel.filterString, on: myViewModel)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment