Reputation: 814
I'd like to know how to open a PDF file that's stored in my Xcode project in OS X Preview. It doesn't have to be Preview, just the default program that opens PDFs on the user's computer. I'm making a reading program. I'm working with Swift 2 with Xcode 7 and I'm making an OS X Cocoa application. Thanks in advance.
Upvotes: 1
Views: 2866
Reputation: 510
Update for Swift 3
if let pdfURL = Bundle.main.url(forResource:"pdfFileName", withExtension: "pdf"){
if NSWorkspace.shared().open(pdfURL) {
print("pdf successfully opened")
}
}
Upvotes: 0
Reputation: 236538
if let pdfURL = NSBundle.mainBundle().URLForResource("pdfFileName", withExtension: "pdf"){
if NSWorkspace.sharedWorkspace().openURL(pdfURL) {
print("pdf successfully opened")
}
}
Upvotes: 4