我有一个在 Swift 3 迁移之前就可以工作的移动 SDK。
我收到以下错误:
无法使用类型为“(使用: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()
}
Run Code Online (Sandbox Code Playgroud)
有问题的行:
request.httpBody = NSString(string: "{}").data(using: String.Encoding.utf8)
Run Code Online (Sandbox Code Playgroud)
我的问题是有没有更好的方法来编写这行代码,或者有没有人遇到过这个问题并成功地将它迁移到 swift 3 …