vvv vvv - 1 month ago 6
Objective-C Question

How to Pass Empty Values to Array?

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?

Answer

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.

Comments