2016-09-26 1 views
0

Swift 3の移行前に動作していたモバイルSDKがあります。Swift 3 - エラー - タイプ '(String.Encodingを使用)の引数リストを使用して'データ 'を呼び出すことができません。

は、私は次のエラーを取得する:

は '(使用:String.Encoding)' タイプの引数リストで 'データ' を呼び出すことはできません ここ

open class func applyTheCode(
     _ theCode: String, 
     forTenant tenant: String, 
     toUserID userID: String, 
     toAccountID accountID: String, 
     withToken token: String, 
     completionHandler: @escaping (_ userInfo: AnyObject?, _ error: NSError?) -> Void) { 

      let url = baseURL.appendingPathComponent("path/to/api/call") 
      let request = NSMutableURLRequest(url: url) 
      request.setValue("application/json", forHTTPHeaderField: "Content-Type") 
      request.setValue(token, forHTTPHeaderField: "token") 
      request.httpMethod = "POST" 
      request.httpBody = NSString(string: "{}").data(using: String.Encoding.utf8) 

      let dataTask = companyDataTaskStatusOKWithRequest(request as URLRequest, withCallback: completionHandler) 
      dataTask.resume() 
} 

問題の行:

request.httpBody = NSString(string: "{}").data(using: String.Encoding.utf8) 

私の質問は、このコード行を書く良い方法があるか、誰もがこの問題に遭遇し、それを迅速な3構文に移行することに成功したことです。


物事は私が試してみた:

request.httpBody = String("{}").data(using: String.Encoding.utf8) 

しかし、私はそれは同じだわからないんだけど、私は誤解される可能性があります。


任意の方向や歓迎のリンクや解答:D

+0

を使用しているデータ(使用。 :.utf8) '? – zneak

+0

'request.httpBody =" {} "。データ(.utf8を使用)' エラーをスローせずに動作します。今実際に動作するかどうかを確認する:Pありがとう。 – Dominique

答えて

2

あなたは何をすべきかNSStringのを、使用している文字列

` "{}" だ方法
request.httpBody = "{}".data(using: String.Encoding.utf8) 
関連する問題