我有下面的代碼,而不是輸出任何一個語句;這兩個語句是輸出:如果聲明輸出兩個參數而不是?
編輯:
大量的試驗和錯誤後,我仍然沒有接近一個解決方案,我都凝結着我的代碼下降到只有最低限度,並在去除所有其他控件試圖解決這一點,仍然沒有工作,這是我的是連接到一個簡單的單開關最少的代碼:
//
進口的UIKit
類的ViewController:的UIViewController {
@IBOutlet weak var mySwitch: UISwitch!
@IBAction func buttonClicked(_ sender: Any) {
let switchOn = mySwitch.isOn
let endpoint = "http://10.0.1.147/setpins"
let urlString = endpoint + "?D2=" + (switchOn ? "0" : "1023")
mySwitch.setOn(!switchOn, animated:true)
var request = URLRequest(url: URL(string: urlString)!)
request.httpMethod = "POST"
let task = URLSession.shared.dataTask(with: request) { data, response, error in
guard error == nil else {
print("error=\(error)")
return
}
// You can print out response object
print("response = \(response)")
}
task.resume()
}
}
BUT:仍然獲得每個參數輸出的輸出同時..
response = Optional(<NSHTTPURLResponse: 0x17402d9e0> { URL: pttp://10.0.1.147/setpins?D1=0 } { status code: 200, headers {
"Access-Control-Allow-Origin" = "*";
Connection = close;
"Content-Length" = 7;
"Content-Type" = "text/plain";
} })
response = Optional(<NSHTTPURLResponse: 0x17002c8a0> { URL: pttp://10.0.1.147/setpins?D2=1023 } { status code: 200, headers {
"Access-Control-Allow-Origin" = "*";
Connection = close;
"Content-Length" = 7;
"Content-Type" = "text/plain";
此外請注意,輸出取決於打開或關閉 –
您的問題不清楚。你能分享更多細節嗎? –
Nazmul,我說的是,上面的if then else語句輸出參數而不是if或else。 –