8466.js 2.3 KB

12
  1. "use strict";(self.webpackChunkmy_application=self.webpackChunkmy_application||[]).push([[8466],{8466:(e,n,r)=>{r.r(n),r.d(n,{default:()=>t});const t='import Foundation\n\nprotocol APIControllerProtocol {\n func didReceiveAPIResults(results: NSArray)\n}\n\nclass APIController {\n var delegate: APIControllerProtocol\n\n init(delegate: APIControllerProtocol) {\n self.delegate = delegate\n }\n\n func get(path: String) {\n let url = NSURL(string: path)\n let session = NSURLSession.sharedSession()\n let task = session.dataTaskWithURL(url!, completionHandler: {data, response, error -> Void in\n println("Task completed")\n if(error != nil) {\n // If there is an error in the web request, print it to the console\n println(error.localizedDescription)\n }\n var err: NSError?\n if let jsonResult = NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions.MutableContainers, error: &err) as? NSDictionary {\n if(err != nil) {\n // If there is an error parsing JSON, print it to the console\n println("JSON Error \\(err!.localizedDescription)")\n }\n if let results: NSArray = jsonResult["results"] as? NSArray {\n self.delegate.didReceiveAPIResults(results)\n }\n }\n })\n\n // The task is just an object with all these properties set\n // In order to actually make the web request, we need to "resume"\n task.resume()\n }\n\n func searchItunesFor(searchTerm: String) {\n // The iTunes API wants multiple terms separated by + symbols, so replace spaces with + signs\n let itunesSearchTerm = searchTerm.stringByReplacingOccurrencesOfString(" ", withString: "+", options: NSStringCompareOptions.CaseInsensitiveSearch, range: nil)\n\n // Now escape anything else that isn\'t URL-friendly\n if let escapedSearchTerm = itunesSearchTerm.stringByAddingPercentEscapesUsingEncoding(NSUTF8StringEncoding) {\n let urlPath = "https://itunes.apple.com/search?term=\\(escapedSearchTerm)&media=music&entity=album"\n }\n }\n\n}'}}]);
  2. //# sourceMappingURL=8466.js.map