Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"collection element of type BOOL" is not an objective-c object

Anyone have a clue why I am getting this?

-(void)postPrimaryEMWithEM:(EM *)em
              exclusive:(BOOL) isExclusive
                 success:(void (^)())onSuccess
                 failure:(void (^)())onFailure {


if(self.accessToken) {


    GenericObject *genObject = [[GenericObject alloc] init];

    [[RKObjectManager sharedManager] postObject:genObject
                                          path:@"users/update.json"
                                    parameters:@{
                                                  ...
                                                 @"em_id"  : ObjectOrNull(em.emID),
                                                 @"exclusive": isExclusive  <-- error message
like image 767
jdog Avatar asked Dec 07 '13 19:12

jdog


2 Answers

Remove the pointer ('*') form your BOOL:

exclusive:(BOOL*) isExclusive

and change:

@"exclusive": isExclusive

to:

@"exclusive": [NSNumber numberWithBool:isExclusive]

or:

// Literal version of above NSNumber
@"exclusive": @(isExclusive)

As a note, NSDictionary cannot store primitive types, including booleans. So you have to encapsulate the value in an object, in this case NSNumber.

like image 54
Chris Avatar answered Nov 11 '22 02:11

Chris


You cannot put a fundamental data type in a dictionary. It must be an object. But you can use [NSNumber numberWithBool:isExclusive] or use the @(isExclusive) syntax:

[[RKObjectManager sharedManager] postObject:genObject
                                       path:@"users/update.json"
                                 parameters:@{
                                              ...
                                             @"em_id"  : ObjectOrNull(em.emID),
                                             @"exclusive": @(isExclusive), ...

I also don't suspect you meant to use BOOL * as your parameter. You presumably intended:

- (void)postPrimaryEMWithEM:(EM *)em
                  exclusive:(BOOL) isExclusive
                    success:(void (^)())onSuccess
                    failure:(void (^)())onFailure {
    ...
}

Again, a BOOL is not an object, so the * syntax was presumably not intended.

like image 41
Rob Avatar answered Nov 11 '22 02:11

Rob