Skip to content

Instantly share code, notes, and snippets.

View novinfard's full-sized avatar

Soheil Novinfard novinfard

View GitHub Profile
@novinfard
novinfard / URLRequest+curlCommand.swift
Last active April 22, 2020 15:28 — forked from dedeexe/URLRequest+curlCommand.swift
Convert URL Request to curl command
extension URLRequest {
public func curl(pretty:Bool = false) -> String {
var data : String = ""
let complement = pretty ? "\\\n" : ""
let method = "-X \(self.httpMethod ?? "GET") \(complement)"
let url = "\"" + (self.url?.absoluteString ?? "") + "\""
var header = ""
@novinfard
novinfard / Alamofire.request.error.handling.swift
Created June 22, 2018 19:57 — forked from perlguy99/Alamofire.request.error.handling.swift
Alamofire Request Error Handling - From their documentation
Alamofire.request(urlString).responseJSON { response in
guard case let .failure(error) = response.result else { return }
if let error = error as? AFError {
switch error {
case .invalidURL(let url):
print("Invalid URL: \(url) - \(error.localizedDescription)")
case .parameterEncodingFailed(let reason):
print("Parameter encoding failed: \(error.localizedDescription)")
print("Failure Reason: \(reason)")