---
title: "lock(before:)"
framework: foundation
role: symbol
role_heading: Instance Method
path: "foundation/nslock/lock(before:)"
---

# lock(before:)

Attempts to acquire a lock before a given time and returns a Boolean value indicating whether the attempt was successful.

## Declaration

```swift
func lock(before limit: Date) -> Bool
```

## Parameters

- `limit`: The time limit for attempting to acquire a lock.

## Return Value

Return Value true if the lock is acquired before limit, otherwise false.

## Discussion

Discussion The thread is blocked until the receiver acquires the lock or limit is reached.

## See Also

### Related Documentation

- [Threading Programming Guide](apple-archive/documentation/Cocoa/Conceptual/Multithreading/Introduction.md)

### Acquiring a Lock

- [try()](foundation/nslock/try().md)
