title: Invalid conversion from throwing function of type
body: <p>I am trying to convert my code over to Swift 2 and I am having issues with this last function. I get the follow error on the declaration of <code>task</code>:</p>
  
  <p><code>Invalid conversion from throwing function of type ... to non throwing type.</code></p>
  
  <pre><code>    func performSearch(searchTerm: String){
      let session = NSURLSession.sharedSession()
  
      let task = session.dataTaskWithURL(urlForQuery(searchTerm)!, completionHandler: { (data: NSData?, response: NSURLResponse?, error: NSError?) -&gt; Void in
          do {
          let result: NSDictionary = try NSJSONSerialization.JSONObjectWithData(data!, options:NSJSONReadingOptions.MutableContainers) as! NSDictionary
          }
          let results: AnyObject? = result.objectForKey("results")
  
          if let testVar: NSMutableArray = results as? NSMutableArray {
                  // Uncomment this to print all feeds
                   //println(testVar)
                  self.searchedPodcasts.removeAllObjects()
                  self.searchedPodcasts.addObjectsFromArray(testVar as [AnyObject])
                  NSNotificationCenter.defaultCenter().postNotificationName("SearchPerformed", object: self)
          }
  
          })
  
          task!.resume()     
  }
  </code></pre>
  
  <p>I have tried the following but it doesn't work either and it also means I can't call task.resume for some reason:</p>
  
  <pre><code>    func performSearch(searchTerm: String){
      let session = NSURLSession.sharedSession()
       do {   
      let task = session.dataTaskWithURL(urlForQuery(searchTerm)!, completionHandler: { (data: NSData?, response: NSURLResponse?, error: NSError?) -&gt; Void in
          do {
          let result: NSDictionary = try NSJSONSerialization.JSONObjectWithData(data!, options:NSJSONReadingOptions.MutableContainers) as! NSDictionary
          }
          let results: AnyObject? = result.objectForKey("results")
  
          if let testVar: NSMutableArray = results as? NSMutableArray {
                  // Uncomment this to print all feeds
                   //println(testVar)
                  self.searchedPodcasts.removeAllObjects()
                  self.searchedPodcasts.addObjectsFromArray(testVar as [AnyObject])
                  NSNotificationCenter.defaultCenter().postNotificationName("SearchPerformed", object: self)
          }
  
          })
      } catch {
            print("error)
      }
          task!.resume()     
  }
  </code></pre>
  
  <p>What can I do to fix it?</p>
  
  <p>Edit: Tried this but the same error is still returned.</p>
  
  <pre><code>     func test(searchTerm: String) {
      let session = NSURLSession.sharedSession()
      do {
          let task = try session.dataTaskWithURL(urlForQuery(searchTerm)!, completionHandler: { (data: NSData?, response: NSURLResponse?, error: NSError?) -&gt; Void in
               let result: NSDictionary = try NSJSONSerialization.JSONObjectWithData(data!, options:NSJSONReadingOptions.MutableContainers) as! NSDictionary
          })
      } catch  {
              print("hello")
          }
      }
  </code></pre>