Last active
March 19, 2023 10:14
-
-
Save katsuyoshi/bb60560dab49591574b5e85229c75e0d to your computer and use it in GitHub Desktop.
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
Optional("Hello World") | |
Optional("Hello Worl") | |
Optional("Hello Wor") |
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
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