0

I have Data. It has empty value and the values are string.In that some of the strings are empty.It does not have value.Now I want to pass empty string values to Array.Application is crashing if I pass empty values(null and empty) to Array.How to check and send value to Array.Can anyone help me please?

3
  • You can't insert a nil or Null Object to an array. Commented Jun 10, 2015 at 7:03
  • 3
    I think NSNull can be added to an array. Commented Jun 10, 2015 at 7:59
  • Are there any scenarios where one would need to insert null into an array? I'd rather have a clean array, and maybe in very specific situations, an array holding indexes of the elements that were null in the first place. Commented Oct 3, 2016 at 7:48

3 Answers 3

1

STEP 1: check string is empty or not

- (NSString *)checkEmpty:(NSString *)check
{
  @try 
  {
    if (check.length==0)
     check = @" ";

    if([check isEqual:[NSNull null]])
     check = @" ";
  }

  @catch (NSException *exception) 
  {
      check = @" ";
  }
}

STEP 2:Adding the String to Array

  [array addObject:[self checkEmpty:strValue]];

If the string value is empty,it takes as above coding after that it passes or adds to array.If the string has value it directly adds to the array.

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

Comments

0

You can use

array_filter();

Which manage empty array.

Comments

0

If I have understood your problem correctly then you are trying to insert a nil value to an array

You cannot insert a nil or a Null value to an array an empty string would be @"".

If this is not what you are looking for please be more elaborate and attach the piece of code along with your question as your question is not clear

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.