<!--
{
  "availability" : [
    "iOS: 11.0.0 -",
    "iPadOS: 11.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.4.0 -",
    "tvOS: 11.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "PDFKit",
  "identifier" : "/documentation/PDFKit/PDFDocument/unlock(withPassword:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "PDFKit"
    ],
    "preciseIdentifier" : "c:objc(cs)PDFDocument(im)unlockWithPassword:"
  },
  "title" : "unlock(withPassword:)"
}
-->

# unlock(withPassword:)

Attempts to unlock an encrypted document.

```
func unlock(withPassword password: String) -> Bool
```

## Parameters

`password`

The password to unlock an encrypted document (you cannot lock an unlocked PDF document by using an incorrect password).

## Return Value

<doc://com.apple.documentation/documentation/Swift/true> if the specified password unlocks the document, <doc://com.apple.documentation/documentation/Swift/false> otherwise.

## Discussion

If the password is correct, this method returns <doc://com.apple.documentation/documentation/Swift/true>, and a `PDFDocumentDidUnlockNotification` notification is sent. Once unlocked, you cannot use this function to relock the document.

If you attempt to unlock an already unlocked document, one of the following occurs:

- If the document is unlocked with full owner permissions, `unlockWithPassword` does nothing and returns <doc://com.apple.documentation/documentation/Swift/true>. The password string is ignored.
- If the document is unlocked with only user permissions, `unlockWithPassword` attempts to obtain full owner permissions with the password string. If the string fails, the document maintains its user permissions. In either case, this method returns <doc://com.apple.documentation/documentation/Swift/true>.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)