Check for NULL values in NSString

You can easily check for null values in NSString, and if the value is null then assign a predefined string. By doing so, you can prevent your iOS app from crashing

//some crazy conversion from webservice
NSString *description = [[results objectAtIndex:i] valueForKey:@"feedbackdescription"];

//let's handle the null
if (description == (id)[NSNull null] || description.length == 0 ) description = @"No feedback";
Did you enjoy this article?
Signup today and receive free updates straight in your inbox. We will never share or sell your email address.

Leave a Reply