【问题标题】:Cannot invoke 'perform' with an argument list of type '(_)'无法使用“(_)”类型的参数列表调用“执行”
【发布时间】:2017-05-15 22:17:23
【问题描述】:

为什么这个 Square 示例直接因为他们的 README 不起作用?

    let callbackURL = URL(string: "OdinMobile://")!
    do {
        let amount = try SCCMoney(amountCents: money, currencyCode: "USD")

        let request : SCCAPIRequest =
            try SCCAPIRequest(
                callbackURL: callbackURL,
                amount: amount,
                userInfoString: userInfoString,
                merchantID: nil,
                notes: notes,
                customerID: nil,
                supportedTenderTypes: supportedTenderTypes,
                clearsDefaultFees: clearsDefaultFees,
                returnAutomaticallyAfterPayment: true
            )

    } catch let error as NSError {
        print(error.localizedDescription)
    }

    do {
        try SCCAPIConnection.perform(request)
    } catch let error as NSError {
        print(error.localizedDescription)
    }

我收到了一个 Cannot invoke 'perform' with an argument list of type '(_)' 和一条附加消息 Overloads for 'perform' exist with these partially matching parameter lists: (SCCAPIRequest), (Selector!)。我希望request 成为一个 SCCAPIRequest,为什么它不作为一个读取?是因为它在do 块中吗?

【问题讨论】:

    标签: swift xcode square-connect


    【解决方案1】:

    do 关键字在其花括号内创建了一个范围,例如 iffor 循环,这意味着您创建的请求在第一个范围内,而在第二个范围内不可用。由于在这两种情况下,您都在做同样的事情并出现相同的错误,因此您只需将 perform 调用移动到同一范围内即可。

    let callbackURL = URL(string: "OdinMobile://")!
    do {
        let amount = try SCCMoney(amountCents: money, currencyCode: "USD")
    
        let request : SCCAPIRequest =
            try SCCAPIRequest(
                callbackURL: callbackURL,
                amount: amount,
                userInfoString: userInfoString,
                merchantID: nil,
                notes: notes,
                customerID: nil,
                supportedTenderTypes: supportedTenderTypes,
                clearsDefaultFees: clearsDefaultFees,
                returnAutomaticallyAfterPayment: true
            )
        try SCCAPIConnection.perform(request)
    } catch let error as NSError {
        print(error.localizedDescription)
    }
    

    【讨论】:

    • @NilsGuillermin 如果有机会,请务必接受这个答案...谢谢伙计!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-13
    相关资源
    最近更新 更多