<!--
{
  "availability" : [
    "macOS: 10.8.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSDocument/lock(_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:objc(cs)NSDocument(im)lockDocument:"
  },
  "title" : "lock(_:)"
}
-->

# lock(_:)

Locks the document in response to the user choosing the Lock menu item.

```
@IBAction func lock(_ sender: Any?)
```

## Parameters

`sender`

The control sending the message.

## Discussion

This is the action of the Lock menu item in a document-based app. This action method invokes the [`lock(completionHandler:)`](/documentation/AppKit/NSDocument/lock(completionHandler:)-6zuhh) method by default.

---

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)