Last active
April 28, 2016 17:42
-
-
Save mikekavouras/e41ec5e75c0346bf9a1144ecf0f81bf4 to your computer and use it in GitHub Desktop.
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
| func getRequest(urlString: String, completion: (NSDictionary) -> Void) { | |
| let defaultSession = NSURLSession(configuration: NSURLSessionConfiguration.defaultSessionConfiguration()) | |
| let urlPath: String = urlString.stringByAddingPercentEncodingWithAllowedCharacters(NSCharacterSet.URLQueryAllowedCharacterSet())! | |
| let url: NSURL = NSURL(string: urlPath)! | |
| let request: NSURLRequest = NSURLRequest(URL: url) | |
| do { | |
| let task = defaultSession.dataTaskWithRequest(request, completionHandler: { (data, response, error) in | |
| do { | |
| if data != nil { | |
| if let jsonResult = try NSJSONSerialization.JSONObjectWithData(data!, options: []) as? NSDictionary { | |
| completion(jsonResult) | |
| } | |
| } | |
| } catch let error as NSError { | |
| print(error.localizedDescription) | |
| } | |
| }) | |
| task.resume() | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment