2017-05-15 21 views
0

この正方形の例は、READMEが機能しないのはなぜですか?'(_)'型の引数リストで '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 
      ) 

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

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

私はOverloads for 'perform' exist with these partially matching parameter lists: (SCCAPIRequest), (Selector!)の追加メッセージをCannot invoke 'perform' with an argument list of type '(_)'を取得します。私はrequestをSCCAPIRequestにしたいのですが、なぜそれが1つではないのですか?それはdoブロックにあるのでですか?

答えて

2

doキーワードは、作成リクエストが最初の範囲内であり、第二では使用できません意味、ifまたはforループのように、その中括弧の内側のスコープを作成します。どちらの場合も同じエラーで同じことをしているので、同じ範囲内で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) 
} 
+0

私は考えましたが、私はそれを自分で試してみました。 –

+0

@NilsGuillerminあなたはチャンスを得るときにこの答えを受け入れるようにしてください...ありがとう! –

関連する問題