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

# lock(whenCondition:before:)

Attempts to acquire a lock before a specified moment in time.

## Declaration

```swift
func lock(whenCondition condition: Int, before limit: Date) -> Bool
```

## Parameters

- `condition`: The condition to match on.
- `limit`: The date by which the lock must be acquired or the attempt will time out.

## Return Value

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

## Discussion

Discussion The receiver’s condition must be equal to condition before the locking operation will succeed. This method blocks the thread’s execution until the lock can be acquired or limit is reached.

## See Also

### Acquiring and Releasing a Lock

- [lock(before:)](foundation/nsconditionlock/lock(before:).md)
- [lock(whenCondition:)](foundation/nsconditionlock/lock(whencondition:).md)
- [try()](foundation/nsconditionlock/try().md)
- [tryLock(whenCondition:)](foundation/nsconditionlock/trylock(whencondition:).md)
- [unlock(withCondition:)](foundation/nsconditionlock/unlock(withcondition:).md)
