jI am building an app where I want to show cleaner's contact information in a UIButton if a cleaner has been assigned to a job, and not show that UIButton otherwise. I have "appointment" objects that have cleaner and cleanerPhone strings as properties. I tried using this to check whether to print string:
if(appt.cleanerPhone)
But this prints the button with a null phone number which isn't helpful. So then I tried
if([appt.cleanerPhone length]>2)
That was working yesterday but just started crashing my app with this error message pointing to the line above:
2015-04-22 18:59:07.165 [640:158880] -[NSNull length]: unrecognized selector sent to instance 0x37afd690
I also tried
if(appt.cleanerPhone && [appt.cleanerPhone length]>2)
But this leads to the same error.
For reference, these all come from a parsed JSON object->NSDictionary. If there is no cleaner, here's what the NSDictionary shows in NSLog:
cleaner = "<null>";
cleanerPhone = "<null>";
So how can I safely and robustly check if a string object of my Appointment class is non-empty? And what's wrong with the two methods above?