Data Protection

PSPDFKit Instant works with iOS data protection. If you set a default data protection level using an entitlement, Instant will use this and there’s nothing more to do.

If you want a different level for documents and annotations stored by Instant, use the dataDirectory class property on InstantClient to access the path where Instant stores data.

If this is the first time Instant is running, create the directory and set the protection type:

try FileManager.default.createDirectory(at: InstantClient.dataDirectory, withIntermediateDirectories: true, attributes: [.protectionKey: FileProtectionType.complete])
[NSFileManager.defaultManager createDirectoryAtURL:PSPDFInstantClient.dataDirectory withIntermediateDirectories:YES attributes:@{NSFileProtectionKey: NSFileProtectionComplete} error:&error];

If you’re upgrading the protection type on an existing installation in an app where Instant has already run, use a directory enumerator. You should decide on an appropriate way to handle errors rather than just logging them:

guard let directoryEnumerator = FileManager.default.enumerator(at: InstantClient.dataDirectory, includingPropertiesForKeys: [], options: [], errorHandler: { url, error -> Bool in
    return true
}) else {
    print("Could not create enumerator for Instant data directory.")
    return false

// `NSEnumerator` is not generic in Swift so we have to deal with `Any`.
while let file = directoryEnumerator.nextObject() as? NSURL {
    try file.setResourceValue(URLFileProtection.complete, forKey: .fileProtectionKey)
NSDirectoryEnumerator<NSURL *> *enumerator = [NSFileManager.defaultManager enumeratorAtURL:PSPDFInstantClient.dataDirectory includingPropertiesForKeys:@[] options:0 errorHandler:^BOOL(NSURL *url, NSError *error) {
    NSLog(@"%@", error);
    return YES;

if (enumerator == nil) {
    NSLog(@"Could not create enumerator for Instant data directory.");

for (NSURL *url in enumerator) {
    NSError *error;

    if (![url setResourceValue:NSURLFileProtectionComplete forKey:NSURLFileProtectionKey error:&error]) {
        NSLog(@"%@", error);