Objective C Boolean Array Objective C Boolean Array arrays arrays

Objective C Boolean Array


Yep, that's exactly what it is: the NS* containers can only store objective-C objects, not primitive types.

You should be able to accomplish what you want by wrapping it up in an NSNumber:

[updated_users replaceObjectAtIndex:index withObject:[NSNumber numberWithBool:YES]]

or by using @(YES) which wraps a BOOL in an NSNumber

[updated_users replaceObjectAtIndex:index withObject:@(YES)]]

You can then pull out the boolValue:

BOOL mine = [[updated_users objectAtIndex:index] boolValue];


Assuming your array contains valid objects (and is not a c-style array):

#define kNSTrue         ((id) kCFBooleanTrue)#define kNSFalse        ((id) kCFBooleanFalse)#define NSBool(x)       ((x) ? kNSTrue : kNSFalse)[updated_users replaceObjectAtIndex:index withObject:NSBool(YES)];


You can either store NSNumbers:

[updated_users replaceObjectAtIndex:index                         withObject:[NSNumber numberWithBool:YES]];

or use a C-array, depending on your needs:

BOOL array[100];array[31] = YES;