     }
     
     /// Called when the background task failed.
-    public func URLSession(session: NSURLSession!, task: NSURLSessionTask!, didCompleteWithError error: NSError!) {
-        if error != nil {
+    public func URLSession(session: NSURLSession, task: NSURLSessionTask, didCompleteWithError error: NSError?) {
+        if let err = error {
             let blocks = self.backgroundTaskMap[session.configuration.identifier]
             if blocks?.failure != nil { //Swift bug. Can't use && with block (radar: 17469794)
-                blocks?.failure!(error, nil)
+                blocks?.failure!(err, nil)
                 cleanupBackground(session.configuration.identifier)
             }
         }

    }
    
    /// The background download finished, don't have to really do anything.
    public func URLSessionDidFinishEventsForBackgroundURLSession(session: NSURLSession!) {
    }
    
    //TODO: not implemented yet.

    ///Returns the response as a string
    public func text() -> String? {
        if let d = self.responseObject as? NSData {
            return  NSString(data: d, encoding: NSUTF8StringEncoding) as? String
        }
        return nil
    }
