First of all, that NSData IS your PDF, no need to convert to another data type or use a library to manipulate it at the moment.
For now, simply save the NSData to your documents directory on iOS, which is not a managed persistent store like CoreData or Realm, nor is it UserDefaults. It's a folder with stuff in it.
Save to Documents Folder:
let data = //the stuff from your web request or other method of getting pdf
let documentsPath = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)[0]
let filePath = "\(documentsPath)/myCoolPDF.pdf"
data.writeToFile(filePath, atomically: true)
Now verify that the file is there and open it on your mac. This is to make sure you've saved an actual PDF and not anything else. This is a two step process. First find out where on earth the file went by printing the location of the documents folder from the iOS simulator:
let paths = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)
let documentsDirectory = paths[0]
print(documentsDirectory)
Now copy that really long filepath and cd [paste location]
in terminal to go there, then open myCoolPDF.pdf
to open it in Preview! It's magical times!
Now that you have verified that you're dealing with an actual PDF it's time to display that in a WebView since it's quite simple unless you've got your own way of doing so.
Note that you still have to make it so the webview shows up, drag one onto your viewController in a storyboard and make an IBOutlet for it.
let url = NSURL(fileURLWithPath: filePath)
let webView = UIWebView()
webView.loadRequest(NSURLRequest(URL: url))
Obviously this is a quick way to make sure you get the basics going, you don't want to force unwrap unsafely using !
.