Braintree error with Xcode 9

Viewed 406

I'm getting a new error in my BTAPIClient.m file since I upgraded to Xcode 9.

the @defaultFirst variable is triggering the following error :

Object of type 'NSNumber *' is not compatible with dictionary value type 'NSString *' .

It's happening in the following line of code : parameters:@{@"default_first": @(defaultFirst)}

I wasn't able to locate anyone else documenting this error. I made no modification to any of the code, this is a fresh Cocoapods install.

- (void)fetchPaymentMethodNonces:(BOOL)defaultFirst completion:(void (^)(NSArray <BTPaymentMethodNonce *> *, NSError *))completion {
if (!self.clientToken) {
NSError *error = [NSError errorWithDomain:BTAPIClientErrorDomain code:BTAPIClientErrorTypeNotAuthorized userInfo:@{ NSLocalizedDescriptionKey : @"Cannot fetch payment method nonces with a tokenization key", NSLocalizedRecoverySuggestionErrorKey : @"This endpoint requires a client token for authorization"}];
    if (completion) {
        completion(nil, error);
    }
    return;
}

[self GET:@"v1/payment_methods"
         parameters:@{@"default_first": @(defaultFirst),
                      @"session_id": self.metadata.sessionId}
         completion:^(BTJSON * _Nullable body, __unused NSHTTPURLResponse * _Nullable response, NSError * _Nullable error) {
             dispatch_async(dispatch_get_main_queue(), ^{
                 if (completion) {
                     if (error) {
                         completion(nil, error);
                     } else {
                         NSMutableArray *paymentMethodNonces = [NSMutableArray array];
                         for (NSDictionary *paymentInfo in [body[@"paymentMethods"] asArray]) {
                             BTJSON *paymentInfoJSON = [[BTJSON alloc] initWithValue:paymentInfo];
                             BTPaymentMethodNonce *paymentMethodNonce = [[BTPaymentMethodNonceParser sharedParser] parseJSON:paymentInfoJSON withParsingBlockForType:[paymentInfoJSON[@"type"] asString]];
                             if (paymentMethodNonce) {
                                 [paymentMethodNonces addObject:paymentMethodNonce];
                             }
                         }
                         completion(paymentMethodNonces, nil);
                     }
                 }
             });
}];
1 Answers

I had the same issue in a project using Cocoapods.

Be sure you haven't updated your dependencies:

  • close xcode
  • clear the pods folder
  • run the pod install not the update
  • build
Related