Is there a short syntax for avoiding passing a nil NSString?
I want to avoid doing this:
if(!str)
str = @"";
[obj someFunc:str];
Here’s what I’d like to do:
[obj someFunc:(str || @"")]
But Objective-C won’t allow it.
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.
The C-way to do in-line conditional expressions is:
It’s known colloquially as the “ternary operator” (the C standard calls it the “conditional operator”). It is used as:
If the condition is non-zero, the
true-expressionis evaluated as the result of the operator, otherwise thefalse-expressionis evaluated as the result.