Created
October 14, 2016 07:17
-
-
Save ahikmatf/f74921ef2f66eff9fdcff17f39076a75 to your computer and use it in GitHub Desktop.
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
// http://ashishkakkad.com/2016/03/how-to-create-a-wrapper-for-alamofire-and-swiftyjson-swift-ios/ | |
// | |
// AFWrapper.swift | |
// AFSwiftDemo | |
// | |
// Created by Ashish on 10/4/16. | |
// Copyright © 2016 Ashish Kakkad. All rights reserved. | |
// | |
import UIKit | |
import Alamofire | |
import SwiftyJSON | |
class AFWrapper: NSObject { | |
class func requestGETURL(_ strURL: String, success:@escaping (JSON) -> Void, failure:@escaping (Error) -> Void) { | |
Alamofire.request(strURL).responseJSON { (responseObject) -> Void in | |
print(responseObject) | |
if responseObject.result.isSuccess { | |
let resJson = JSON(responseObject.result.value!) | |
success(resJson) | |
} | |
if responseObject.result.isFailure { | |
let error : Error = responseObject.result.error! | |
failure(error) | |
} | |
} | |
} | |
class func requestPOSTURL(_ strURL : String, params : [String : AnyObject]?, headers : [String : String]?, success:@escaping (JSON) -> Void, failure:@escaping (Error) -> Void){ | |
Alamofire.request(strURL, method: .post, parameters: params, encoding: JSONEncoding.default, headers: headers).responseJSON { (responseObject) -> Void in | |
print(responseObject) | |
if responseObject.result.isSuccess { | |
let resJson = JSON(responseObject.result.value!) | |
success(resJson) | |
} | |
if responseObject.result.isFailure { | |
let error : Error = responseObject.result.error! | |
failure(error) | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment