I tried something along the lines of:
if(myString != nil && myString.length) { ... }
And got:
-[NSNull length]: unrecognized selector sent to instance
Does Objective-C not short-circuit after the first condition fails?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Objective-C does support short-circuit evaluation, just like C.
It seems that in your example
myStringisNSNulland notnil, thereforemyString != nilis true.NSNull is a singleton and is used to represent
nilwhere only objects are allowed, for example in an NSArray.Btw, normally, people write
if (!myString && myString.length == 0). Comparing tonilis quite ugly. Also, I’d compare the length to 0. That seems to be more clear.