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.MPG– MPG2015-06-10 07:03:39 +00:00Commented Jun 10, 2015 at 7:03
-
3I think NSNull can be added to an array.Ryan– Ryan2015-06-10 07:59:25 +00:00Commented 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.Gil Sand– Gil Sand2016-10-03 07:48:37 +00:00Commented Oct 3, 2016 at 7:48
Add a comment
|
3 Answers
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
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