Using PSPDFKitSwift

PSPDFKitSwift.framework is a set of wrappers and extensions that improve the Swift experience when working with PSPDFKit.

Usage

To use the Swift wrappers and extensions, you need to import the PSPDFKitSwift module:

1
import PSPDFKitSwift

Once this is done, you can work with the PSPDFKit framework as usual. The only change you will notice is that there are several improvements to the framework APIs when working with Swift. Check out the documentation to discover all the wrapped APIs you may want to adopt in your code.

Note: There is no need to import the PSPDFKit module separately.

Getting Started

Make sure you have access to PSPDFKit either as a customer or by signing up for a free trial.

Using CocoaPods

We assume you are familiar with CocoaPods. If not, please consult the CocoaPods documentation first.

To get a CocoaPods-based integration up and running, you need to add PSPDFKitSwift as a dependency and then modify your existing PSPDFKit integration to use the PSPDFKit/Swift subspec.

Your Podfile should look like this:

Copy
1
2
3
4
5
6
7
8
9
10
# Replace `YourAppName` with your app's target name.

pod 'PSPDFKitSwift', :git => 'https://github.com/PSPDFKit/PSPDFKitSwift.git', :tag => '1.0.0'

target :YourAppName do
  use_frameworks!

  # Replace `YOUR_COCOAPODS_KEY` with your own.
  pod 'PSPDFKit/Swift', podspec: 'https://customers.pspdfkit.com/cocoapods/YOUR_COCOAPODS_KEY/latest.podspec'
end

Note: PSPDFKitSwift is not published in the public CocoaPods Specs. You have to reference the pod with the Git repository, as shown in the example above. Also, make sure to replace YourAppName with your app name and YOUR_COCOAPODS_KEY with your own key provided by PSPDFKit GmbH. If you are an existing customer, you can find your key in the customer portal. Otherwise, you can request an evaluation license.

Now run pod install. Afterward, you should be able to build and run your project without errors.

Manual Setup

Note: Manual setup is only for experts, so you should know what you are doing. If you are unsure of what to do, please use CocoaPods or Carthage instead.

First, build the PSPDFKitSwift framework via the following steps:

  • Clone [email protected]:PSPDFKit/PSPDFKitSwift.git.
  • Copy PSPDFKit.framework into PSPDFKitSwift/Frameworks.
  • Open the terminal and navigate to the PSPDFKitSwift directory.
  • Run rake compile:macos.

You should now have PSPDFKitSwift.framework in the Build folder. Next, add PSPDFKit.framework and PSPDFKitSwift.framework to your project:

  • Follow the Getting Started instructions for PSPDFKit.

  • Perform the first two steps from the Integrating the Dynamic Framework section in the above Getting Started guide, and add PSPDFKitSwift to your app, similar to how you did it with PSPDFKit above. You may also want to set up your test targets accordingly. Be sure to adapt the path for the Run Script build phase for PSPDFKitSwift.

You should now be able to build and run your app.

Limitations

PSPDFKitSwift is a work in progress, and we have more plans for improving upon it in the future. As such, we do not yet guarantee API stability. However, this shouldn’t stop you from using it, as changes will usually be easy to adopt.

Technical notes:

  • All PSPDFKitSwift source files live in the Sources directory.
  • PSPDFKit (and PSPDFKitUI modules on iOS) are reexported automatically.
  • PSPDFKitSwift-Private.xcodeproj is used internally by the PSPDFKit team. Always use PSPDFKitSwift.xcodeproj.

Known Issues

Linker warning when building without Carthage: In order to support Carthage out of the box with per-customer PSPDFKit URLs, we’ve added the parent Carthage build folder to Framework Search Paths. When building without Carthage, this produces the following warning:

1
ld: warning: directory not found for option '-F/Users/desktopuser/Projects/PSPDFKit/PSPDFKitSwift/../../../Carthage/Build/iOS'