0

I have a mutable array of checked box

NSMutableArray *arrayOfCheckedBox = [NSMutableArray arrayWithObjects:namePropertyString, lastNamePropertyString, companyPropertyString, workEmailPropertyString, personalEmailPropertyString, workPhonePropertyString, cellNumberPropertyString, nil];
    [arrayOfCheckedBox removeObjectIdenticalTo:[NSNull null]]; //not working
    NSLog(@"array of check box = %@", arrayOfCheckedBox);

If I click on check boxes at index 0, 1 and 4, it will only collect object at indexes 0 and 1 only and will not detect index 4 at all.

I get the values at the selected index in log before getting it in arrayOfCheckedBox. How to get checked values in this case?

Deepak Thakur
  • 3,453
  • 2
  • 37
  • 65

3 Answers3

1

The problem is that you're hitting a nil value, so the arrayWithObjects: method thinks you're at the end of the list of objects.

Something like this will work:

NSMutableArray *arrayOfCheckedBox = [NSMutableArray arrayWithCapacity:7];

if (namePropertyString)
    [arrayOfCheckedBox addObject:namePropertyString];

if (lastNamePropertyString)
    [arrayOfCheckedBox addObject:lastNamePropertyString];
Aaron Brager
  • 65,323
  • 19
  • 161
  • 287
0

I would suggest storing the check box values in an array of BOOLs. Wrap them in NSNumbers first and unwrap them to retrieve them.

Wrap to store,

[NSNumber numberWithBool:YES]] 

Unwrap to retrieve,

[[your_array objectAtIndex:index] boolValue]
paulvs
  • 11,963
  • 3
  • 41
  • 66
  • You can wrap them in an NSNumber, `[NSNumber numberWithBool:YES]]`, then unwrap them with `[[your_array objectAtIndex:index] boolValue];` – paulvs Dec 02 '13 at 13:52
-1

For null values appear to be string literals @"" rather than the NSNull.So use following way to remove null object :

    NSLog(@"%d", [arrayOfCheckedBox count]);
    NSString *nullString = @"<null>";
    [arrayOfCheckedBox removeObject:nullString];
    NSLog(@"%d", [arrayOfCheckedBox count]);
Divya Bhaloidiya
  • 5,018
  • 2
  • 25
  • 45
  • "" only appears in some printing or formatting paths. It's not equivalent to nil or [NSNull null] in any other context. – Greg Parker Dec 06 '13 at 03:08