PromiseKit 框架 - 对成员的引用不明确 'then()'

PromiseKit Framework - Ambiguous reference to member 'then()'

我正在使用 PromiseKit 框架版本 1.7.7(我需要使用这个版本,因为另一个框架需要它)。

所以,在这个使用PromiseKit框架的框架中有这个方法:

- (PMKPromise *)paymentTokenForCreditCard:(GNCreditCard *)creditCard {
    NSDictionary *cardDict = [creditCard paramsDicionary];
    NSString *jsonCard = [self getJSONStringFromDictionary:cardDict];

    return [self encryptData:jsonCard]
    .then(^(NSString *encryptedData){
        NSDictionary *params = @{@"data":encryptedData};
        return [self request:kGNApiRouteSaveCard method:@"POST" params:params];
    })
    .then(^(NSDictionary *response){
        return [[GNPaymentToken alloc] initWithDictionary:response];
    });
}

它展示了如何使用它的例子:

GNConfig *gnConfig = [[GNConfig alloc] initWithAccountCode:@"YOUR_ACCOUNT_CODE" sandbox:YES];

GNApiEndpoints *gnApi = [[GNApiEndpoints alloc] initWithConfig:gnConfig];

GNCreditCard *creditCard = [[GNCreditCard alloc] init];
creditCard.number = @"4012001038443335";
creditCard.brand = kGNMethodBrandVisa;
creditCard.expirationMonth = @"05";
creditCard.expirationYear = @"2018";
creditCard.cvv = @"123";

[gnApi paymentTokenForCreditCard:creditCard]
.then(^(GNPaymentToken *paymentToken){
NSLog(@"%@", paymentToken.token);
})
.catch(^(GNError *error){
NSLog(@"An error occurred: %@", error.message);
});

好吧,我是如何使用 Swift 而不是 Object-C 的,我正在尝试以这种方式使用它:

let gnConfig = GNConfig(accountCode: "3f62976bea79971730b67cd62806c256", sandbox: true)
let gnEndpoints = GNApiEndpoints(config: gnConfig)

let gnCreditCard: GNCreditCard! = GNCreditCard(number: "4012001038443335", brand: kGNMethodBrandVisa, expirationMonth: "05", expirationYear: "2018", cvv: "123")

gnEndpoints?.paymentToken(for: gnCreditCard).then({ tokenPagamento in
    if let aToken = tokenPagamento?.token {
        print("\(aToken)")
    }
}).catch({ error in
    if let aMessage = error?.message {
        print("An error occurred: \(aMessage)")
    }
})

它向我显示了这个错误:

Ambiguous reference to member 'then()'

我该如何解决?

试试下面的代码。承诺的事情应该有效。根据需要修改。

gnEndpoints?.paymentToken(for: gnCreditCard).then({ token -> () in
   if let token = token as? GNPaymentToken {
      print(token)
   }
}, { (error) -> () in
   // catch your error
})