title: How to solve error: "Invalid type in JSON write (NSConcreteData)"
body: <p>I'm trying to write some code to validate a subscription on my iOS App.  I'm following this tutorial: <a href="http://savvyapps.com/blog/how-setup-test-auto-renewable-subscription-ios-app/" rel="nofollow">http://savvyapps.com/blog/how-setup-test-auto-renewable-subscription-ios-app/</a></p>
  
  <p>It's not in Swift 2.0, so I had to convert some of the code, but I'm having trouble with this line:</p>
  
  <pre><code>let requestData = try! NSJSONSerialization.dataWithJSONObject(receiptDictionary, options: NSJSONWritingOptions.PrettyPrinted) as NSData!
  </code></pre>
  
  <p>When it hits that line, it prints this error message: </p>
  
  <blockquote>
    <p>Terminating app due to uncaught exception
    'NSInvalidArgumentException', reason: 'Invalid type in JSON write
    (NSConcreteData)'</p>
  </blockquote>
  
  <p>Here's the whole function:</p>
  
  <pre><code>func validateReceipt() {
      print("Validating")
  
      if let receiptPath = NSBundle.mainBundle().appStoreReceiptURL?.path where NSFileManager.defaultManager().fileExistsAtPath(receiptPath) {
          print("Loading Validation")
          let receiptData = NSData(contentsOfURL:NSBundle.mainBundle().appStoreReceiptURL!)
          print(receiptData)
          let receiptDictionary = ["receipt-data" :
              receiptData!.base64EncodedDataWithOptions([]), "password" : "placeholder"]
          let requestData = try! NSJSONSerialization.dataWithJSONObject(receiptDictionary, options: NSJSONWritingOptions.PrettyPrinted) as NSData!
  
          let storeURL = NSURL(string: "https://sandbox.itunes.apple.com/verifyReceipt")!
          let storeRequest = NSMutableURLRequest(URL: storeURL)
          storeRequest.HTTPMethod = "POST"
          storeRequest.HTTPBody = requestData
  
          let session = NSURLSession(configuration: NSURLSessionConfiguration.defaultSessionConfiguration())
  
          session.dataTaskWithRequest(storeRequest, completionHandler: { (data, response, connection) -&gt; Void in
  
              if let jsonResponse: NSDictionary = try! NSJSONSerialization.JSONObjectWithData(data!, options:NSJSONReadingOptions.MutableContainers) as?
                  NSDictionary, let expirationDate: NSDate = self.formatExpirationDateFromResponse(jsonResponse) {
                      print(expirationDate)
                      //self.updateIAPExpirationDate(expirationDate)
              }
          })
      }
  }
  </code></pre>
  
  <p>I haven't done in-app purchases before, so I'm a bit new to this.  Thanks in advance for your help!</p>