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
name = UITextFieldTextDidChangeNotification, object = Optional(<UITextField: 0x14c836800; frame = (150 300; 200 20); opaque = NO; focused = YES; gestureRecognizers = <NSArray: 0x6000027e7cf0>; text = 'Hello World'; borderStyle = None; background = <_UITextFieldNoBackgroundProvider: 0x600002bd0500: textfield=<UITextField 0x14c836800>>; layer = <CALayer: 0x600002985b80>>), userInfo = nil | |
name = UITextFieldTextDidChangeNotification, object = Optional(<UITextField: 0x14c836800; frame = (150 300; 200 20); opaque = NO; focused = YES; gestureRecognizers = <NSArray: 0x6000027e7cf0>; text = 'Hello Worl'; borderStyle = None; background = <_UITextFieldNoBackgroundProvider: 0x600002bd0500: textfield=<UITextField 0x14c836800>>; layer = <CALayer: 0x600002985b80>>), userInfo = nil | |
name = UITextFieldTextDidChangeNotification, object = Optional(<UITextField: 0x14c836800; frame = (150 300; 200 20); opaque = NO; focused = YES; gestureRecognizers = <NSArray: 0x6000027e7cf0>; text = 'Hello Wor'; borderStyle = None; background = <_UITextFieldNoBackgroundProvider: 0x600002bd0500: textfield=<UITextField 0x14c836800>>; layer = <CALayer: 0x600002985b80>>), userInfo = nil |
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) | |
.sink(receiveCompletion: { print ($0) }, | |
receiveValue: { print ($0) }) | |
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