---
title: "lock(completionHandler:)"
framework: appkit
role: symbol
role_heading: Instance Method
path: "appkit/nsdocument/lock(completionhandler:)-6zuhh"
---

# lock(completionHandler:)

Prevents the user from making further changes to the document.

## Declaration

```swift
func lock(completionHandler: ((Bool) -> Void)? = nil)
```

```swift
func lock() async -> Bool
```

## Parameters

- `completionHandler`: The completion handler block object passed in to be invoked after locking is completed, regardless of success or failure of locking.

## Discussion

Discussion By default, this method first ensures that any editor who has registered using Cocoa Binding’s NSEditorRegistration informal protocol has committed all changes and then autosaves the document, if necessary, before attempting to lock it using the lock(completionHandler:) method. Upon successful locking, the isLocked property is set to [YES]. Documents whose fileURL property is set to nil cannot be locked.

## See Also

### Locking the Document

- [lock(_:)](appkit/nsdocument/lock(_:).md)
- [unlock(_:)](appkit/nsdocument/unlock(_:).md)
- [lock(completionHandler:)](appkit/nsdocument/lock(completionhandler:)-161qv.md)
- [unlock(completionHandler:)](appkit/nsdocument/unlock(completionhandler:)-8p8zd.md)
- [unlock(completionHandler:)](appkit/nsdocument/unlock(completionhandler:)-6m7rh.md)
- [isLocked](appkit/nsdocument/islocked.md)
