ios - what's the bulletproof method to check if NSString is empty/null? -


this question has answer here:

ji building app want show cleaner's contact information in uibutton if cleaner has been assigned job, , not show uibutton otherwise. have "appointment" objects have cleaner , cleanerphone strings properties. tried using check whether print string:

if(appt.cleanerphone) 

but prints button null phone number isn't helpful. tried

if([appt.cleanerphone length]>2) 

that working yesterday started crashing app error message pointing line above:

2015-04-22 18:59:07.165 [640:158880] -[nsnull length]: unrecognized selector sent instance 0x37afd690 

i tried

if(appt.cleanerphone && [appt.cleanerphone length]>2) 

but leads same error.

for reference, these come parsed json object->nsdictionary. if there no cleaner, here's nsdictionary shows in nslog:

    cleaner = "<null>";     cleanerphone = "<null>"; 

so how can safely , robustly check if string object of appointment class non-empty? , what's wrong 2 methods above?

you getting data json or data interchange format. conversion makes null [nsnull null] objects. need type check value before use it. try:

if ([appt.cleanerphone iskindofclass:[nsstring class]] && ([appt.cleanerphone length] > 2)) {...} 

Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -