Here's the code:
- (IBAction) charlieInputText:(id)sender { //getting value from text field when entered charlieInputSelf = [sender stringValue]; if (charlieInputSelf != @"") { //(send field if not empty } }
This sends it even when the field is empty; therefore, this does not work as I want it to.
Simply checks for nil and if length of text length is greater than 0 - not empty
if (textField.text && textField.text.length > 0) { /* not empty - do something */ } else { /* what ever */ }
We already have inbuilt method that return boolean value that indicates whether the text-entry objects has any text or not.
// In Obj-C if ([textField hasText]) { //* Do Something you have text }else{ /* what ever */ } // In Swift if textField.hasText { //* Do Something you have text }else{ /* what ever */ }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With