본문 바로가기

iOS/swift

네트워크

반응형
let loginURLString = "http://localhost:3000/loginUsers"

let param = [
"userName" : userNameTextField.text ?? "",
"password" : passwordTextField.text ?? ""
]

var urlComponents = URLComponents(string: loginURLString)
urlComponeents?.query =  param.queryString

guard let hasURL= urlComponents?.url else {
return 
}

URLSession.shared.dataTask(with: hasURL) { (data, response, error) in

}

extension Dictionary {
 var queryString: String {
 var output = ""
 for (key, value) in self {
  output = output + "\(key)=\(value)&"
 }

 output = String(output.dropLast())
 return output
 }
}
반응형

'iOS > swift' 카테고리의 다른 글

GCD(Grand Central Patch)  (0) 2020.07.18
URLSession  (0) 2020.07.04
Swift error: missing argument label 'name:' in call  (0) 2020.06.08
[swift] ViewController간 이동  (0) 2020.05.01
xcode에서 iPhone연결하기  (0) 2020.04.26

]