在Swift3中,我之前使用以下方法将Bool转换为Int
let _ = Int(NSNumber(value: false))
Run Code Online (Sandbox Code Playgroud)
转换为Swift4后,我得到了一个"'init'被弃用"警告.怎么办呢?
我对这篇文章的问题非常相似,但我不完全理解答案.我已经创建了一个完成处理程序,但它似乎没有按预期工作.
func updateTeam(teamID: Int) {
startConnection {NSArray, Int in
//Do things with NSArray
}
}
func startConnection(completion: (NSArray, Int) -> Void) {
let url = URL(string: "http://www.example.com/path")
var request : URLRequest = URLRequest(url: url!)
request.httpMethod = "POST"
let postString = "a=\(Int(teamInput.text!)!)"
request.httpBody = postString.data(using: .utf8)
let dataTask = URLSession.shared.dataTask(with: request) {
data,response,error in
print("anything")
do {
if let jsonResult = try JSONSerialization.jsonObject(with: data!, options: []) as? NSDictionary {
self.teamResult = jsonResult
print(jsonResult)
}
} catch let error as …Run Code Online (Sandbox Code Playgroud)