<!--
{
  "availability" : [
    "iOS: 2.0.0 -",
    "iPadOS: 2.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.0.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/NSConditionLock/lock(whenCondition:before:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSConditionLock(im)lockWhenCondition:beforeDate:"
  },
  "title" : "lock(whenCondition:before:)"
}
-->

# lock(whenCondition:before:)

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

```
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

<doc://com.apple.documentation/documentation/Swift/true> if the lock is acquired within the time limit, <doc://com.apple.documentation/documentation/Swift/false> otherwise.

## 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.

---

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)