View Full Version : Testing an NSTextField objectValue for Data?

Dec 31, 2008, 11:18 AM
I'm working through the chapter 6 Hillegass (third edition) challenge where he asks you to make a "To Do" list. I have an NSTextField variable called "taskTextField". The user types a task in the NSTextField and clicks an "add" button which then enters the value in the table.

My question is this ... I don't want the user to simply push, "add" without typing anything in the NSTextField. I tried this to obtain that functionality:

if ( [taskTextField objectValue] != nil )

but that didn't cut it. When I clicked on "add" it entered the empty task into the table.

I got it to work by doing this:

if ( [[taskTextField stringValue] length] != 0 )

but it seems silly to have to it that way. How do I test for an 'empty' object? There has to be an easy way to do that ... ? Thanks.