0

Many programming languages have an easier way to handle if a string is null. Is there anything with NSSTring that you can use without having to use if then.

I am showing some data in a tableview cell and sometimes the data is really null I dont want the ugly (NULL) showing up in my cell.

Thanks!

3
  • Just out of curiosity, what kind of alternatives do these many other programming languages offer to deal with null values, aside from if statements? Commented Nov 4, 2011 at 6:08
  • Like there is a ISNULL I believe in SQL and VB.NET for example. It will let you set a default value if the value is null. I can easily do if then's but I wondered if there was a way to simplify it. Commented Nov 4, 2011 at 6:17
  • Is there anything in particular preventing you from creating an ISNULL function in Objective-C? To me it seems rather straightforward. id ObjectOrPlaceholder(id object, id placeholder) { return object != nil ? object : placeholder; } Commented Nov 4, 2011 at 6:39

1 Answer 1

2

SQL is not a procedural language, this is why you need an inline function like ISNULL, which can be used within SELECT statement for example. It does not mean it is simpler, it was designed for a specific need.

The ternary conditional operator ?: may be used in C to have a similar implementation:

(condition ? YES : NO)

where condition is the actual comparison. Otherwise, you can design any custom function you need.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.