From the following code, I want to determine if the text is empty (contains nothing), but I can't access its value. The Validator class is to receive various objects, determine the object's type, and then check it it contains valid text. If not, return a message about the problem. The code follows:
import Foundation
import Cocoa
class Validator {
let alertTitle = "Entry Error"
let alertMsgA = " is a REQUIRED FIELD, please supply it!"
let alertMsgB = " is a an invalid date, please correct it."
let alertMsgC = " is a an invalid phone number, please correct it."
func isPresent(sender: Any) -> Bool {
if sender is NSTextField {
if sender.isEmpty { /
return false
}
}
return true
}
}
your text field probably has an IBOutlet such as :
@IBOutlet var myTextField : UITextField!
then, you can test through all possible fields with :
if sender === myTextField { ....
or you can set a tag in IB to the textField and test
switch sender.tag {
case 1 : doForFirstField
case 2 : ...
}