Skip to content

Instantly share code, notes, and snippets.

@katsuyoshi
Last active March 19, 2023 10:14
Show Gist options
  • Save katsuyoshi/bb60560dab49591574b5e85229c75e0d to your computer and use it in GitHub Desktop.
Save katsuyoshi/bb60560dab49591574b5e85229c75e0d to your computer and use it in GitHub Desktop.
Optional("Hello World")
Optional("Hello Worl")
Optional("Hello Wor")
import UIKit
import PlaygroundSupport
import Combine
class MyViewController : UIViewController {
var sub: AnyCancellable!
override func loadView() {
let view = UIView()
view.backgroundColor = .white
let label = UILabel()
label.frame = CGRect(x: 150, y: 200, width: 200, height: 20)
label.text = "Hello World!"
label.textColor = .black
view.addSubview(label)
let textField = UITextField()
textField.frame = CGRect(x:150, y: 300, width: 200, height: 20)
textField.text = "Hello World!"
textField.textColor = .black
sub = NotificationCenter.default
.publisher(for: UITextField.textDidChangeNotification, object: textField)
.map( { ($0.object as! UITextField).text } )
.sink(receiveCompletion: { print ($0) },
receiveValue: { print ($0 as Any) })
view.addSubview(textField)
self.view = view
}
}
// Present the view controller in the Live View window
PlaygroundPage.current.liveView = MyViewController()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment