This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Não esqueca de importar o Foundation | |
func postRequest(url: String, params: [String: String], | |
completion: @escaping ([String: Any]?, Error?) -> Void){ | |
//URL válida | |
guard let URL = URL(string: url) else { | |
completion(nil, nil) | |
return | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Chamando a funcão POST | |
postRequest(url: url, params: params){ | |
(result, err) in | |
if let res:Bool = (result?.values.first as? Bool) { | |
if(res) { | |
//Aqui res podera assumir dois valores, true ou false | |
print("sua requisicao foi realizada com sucesso") | |
} else { | |
print("a requisicao nao funcionou") | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Aqui vão os parâmetros da sua requisição | |
let params = [ | |
"nome":"Matheus Gois", | |
"sobreNome":"Gois", | |
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func postRequest(url:String, params: [String: String], | |
completion: @escaping ([String: Any]?, Error?) -> Void){ | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Coloque a URL da sua API aqui | |
let url = "http://www.SuaURL.com" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func postRequest(url: String, params: [String: String], | |
completion: @escaping ([String: Any]?, Error?) -> Void){ | |
// URL válida | |
guard let URL = URL(string: url) else { | |
completion(nil, nil) | |
return | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Não esqueca de importar o Foundation | |
func postRequest(url: String, params: [String: String], | |
completion: @escaping ([String: Any]?, Error?) -> Void){ | |
//URL válida | |
guard let URL = URL(string: url) else { | |
completion(nil, nil) | |
return | |
} | |
//Cria a representacão da requisição |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Não esqueca de importar o Foundation | |
func postRequest(url: String, params: [String: String], | |
completion: @escaping ([String: Any]?, Error?) -> Void){ | |
//URL válida | |
guard let URL = URL(string: url) else { | |
completion(nil, nil) | |
return | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Não esqueca de importar o Foundation | |
func getRequest(url: String, | |
completion: @escaping ([String: Any]?, Error?) -> Void){ | |
//URL válida | |
guard let URL = URL(string: url) else { | |
completion(nil, nil) | |
return | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Coloque a URL da sua API aqui | |
let url = "https://jsonplaceholder.typicode.com/todos/1" |
OlderNewer