Skip to content

Instantly share code, notes, and snippets.

@feighter09
Last active November 6, 2016 05:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save feighter09/883d8364f411071ecb27577b8df3904d to your computer and use it in GitHub Desktop.
Save feighter09/883d8364f411071ecb27577b8df3904d to your computer and use it in GitHub Desktop.
import Alamofire
import SwiftyJSON
protocol NetworkClientType {
func makeRequest<Response: JSONDecodable>(url: String,
params: [String : AnyObject],
callback: (Response?, ErrorType?) -> Void)
}
struct NetworkClient: NetworkClientType {
func makeRequest<Response: JSONDecodable>(url: String,
params: [String : AnyObject],
callback: (Response?, ErrorType?) -> Void)
{
request(.POST, url, parameters: params).response { _, _, data, error in
if let jsonData = data where error == nil {
let json = JSON(data: jsonData)
let response = Response(json: json)
callback(response, nil)
}
else {
callback(nil, error)
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment