STEVEN WEBBER
asked on
TextField Changed Notification Problem
I am trying to run code in swift when a textField (in macOS) changes. I have tried:
override func viewDidLoad() {
super.viewDidLoad()
let name = "NSNotificationTextFieldCh anged"
NotificationCenter.default .addObserv er(self, selector: Selector(fieldTextDidChang e),
Notification(name: Notification.Name(rawValue : name)), object: nil)
}
func fieldTextDidChange(notific ation: NSNotification) {
errorMessage.stringValue = ""
errorMessage.isHidden = true
}
but I get the error "Cannot convert value of type '(NSNotification) -> ()' to expected argument type 'String'
Any ideas?
override func viewDidLoad() {
super.viewDidLoad()
let name = "NSNotificationTextFieldCh
NotificationCenter.default
Notification(name: Notification.Name(rawValue
}
func fieldTextDidChange(notific
errorMessage.stringValue = ""
errorMessage.isHidden = true
}
but I get the error "Cannot convert value of type '(NSNotification) -> ()' to expected argument type 'String'
Any ideas?
ASKER
Thanks Hamidreza Vakilian. I will try this.
This question needs an answer!
Become an EE member today
7 DAY FREE TRIALMembers can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Swift:
Open in new window
andOpen in new window
Swift 2.2:
Open in new window
andOpen in new window
Swift 3:
Open in new window
andOpen in new window