Home > DeveloperSection > Forums > Utilizing array in Objective-C?
Jayne Spooner
Jayne Spooner

Total Post:21

Posted on    December-26-2015 4:18 AM

 iPhone iPhone  Ios  Objective C 

 1 Reply(s)
 671  View(s)
Rate this:

I want to utilize boolean array in Objective C programming. I have got it mostly set up, but the compiler throws a warning at the following statement:
[userObj replaceObjectAtIndex:index withObject:YES];
YES is simply not an object.(This is my view)

It is a primitive, regardless I need to do this, and would greatly appreciate advice on how to accomplish it.

Tarun Kumar

Total Post:214

Posted on    December-27-2015 10:37 PM

We can do this by wrapping it up in an NSNumber, like this:

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

or we can use @(YES), it will wraps a BOOL in an NSNumber, like this:

[userObj replaceObjectAtIndex:index withObject:@(YES)]];

Now, we can use it by pulling out the bool value, like this:

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

Don't want to miss updates? Please click the below button!

Follow MindStick