Created
January 5, 2016 10:32
-
-
Save Kievkao/a7fbab0283d8e979c5da to your computer and use it in GitHub Desktop.
Alamofire network router snippet
This file contains hidden or 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
| import Alamofire | |
| enum NetworkRouter: URLRequestConvertible { | |
| static let baseURLString = "xxx" | |
| case UserLogin(Int) | |
| var URLRequest: NSMutableURLRequest { | |
| let requestComponents : (path: String, parameters: [String: AnyObject]) = { | |
| let requestPath: String | |
| let requestParameters: [String : AnyObject] | |
| switch self { | |
| case .UserLogin (let userId): | |
| requestPath = "/xxx" | |
| requestParameters = ["xxx": userId] | |
| } | |
| return (requestPath, requestParameters) | |
| }() | |
| let URL = NSURL(string: NetworkRouter.baseURLString) | |
| let URLRequest = NSURLRequest(URL: URL!.URLByAppendingPathComponent(requestComponents.path)) | |
| let encoding = Alamofire.ParameterEncoding.URL | |
| return encoding.encode(URLRequest, parameters: requestComponents.parameters).0 | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment