Skip to content

Instantly share code, notes, and snippets.

@igorsilvadev
Created January 11, 2023 22:20
Show Gist options
  • Save igorsilvadev/61fc666598c8dfb243bb19e83ec2891b to your computer and use it in GitHub Desktop.
Save igorsilvadev/61fc666598c8dfb243bb19e83ec2891b to your computer and use it in GitHub Desktop.
A Textfield extension to add a publisher to text property
//
// TextField+TextPublisher.swift
//
import UIKit
import Combine
extension UITextField {
var textPublisher: AnyPublisher<String, Never> {
NotificationCenter.default.publisher(for: UITextField.textDidChangeNotification,
object: self).compactMap { ($0.object as? UITextField)?.text }
.eraseToAnyPublisher()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment