Created
January 11, 2023 22:20
-
-
Save igorsilvadev/61fc666598c8dfb243bb19e83ec2891b to your computer and use it in GitHub Desktop.
A Textfield extension to add a publisher to text property
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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