Objective C Boolean Array

前端 未结 6 987
北恋
北恋 2020-12-08 18:54

I need to utilize an array of booleans in objective-c. I\'ve got it mostly set up, but the compiler throws a warning at the following statement:

[updated_use         


        
6条回答
  •  感情败类
    2020-12-08 19:44

    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];

提交回复
热议问题