cocoa - Check if the NSTextView is empty in OSX -
i trying display message if nstextview empty(the user hasn't entered in textview) couldnt find appropriate built in method.in case of nstextfiled simple.
if(countelements(emailtextfield.stringvalue) == 0) is there substitute nstextview in mac
get access nstextstorage object held nstextview, , use (read-only) length property count elements in storage object's underlying string property:
// mark: nstextviewdelegate implementation func textdidchange(notification: nsnotification) { if let textview = notification.object as? nstextview { if let storage = textview.textstorage { if storage.length == 0 { // text-view empty } } } } if @ nstextstorage class reference you'll see in fact nsattributedstring subclass. nsattributedstring has string property, , length property - it's length property we're using determine if string 'empty'.
Comments
Post a Comment