---
title: NSConditionLock
framework: foundation
role: symbol
role_heading: Class
path: foundation/nsconditionlock
---

# NSConditionLock

A lock that can be associated with specific, user-defined conditions.

## Declaration

```swift
class NSConditionLock
```

## Overview

Overview Using an NSConditionLock object, you can ensure that a thread can acquire a lock only if a certain condition is met. Once it has acquired the lock and executed the critical section of code, the thread can relinquish the lock and set the associated condition to something new. The conditions themselves are arbitrary: you define them as needed for your application.

## Topics

### Initializing an NSConditionLock Object

- [init(condition:)](foundation/nsconditionlock/init(condition:).md)

### Accessing the Condition

- [condition](foundation/nsconditionlock/condition.md)

### Acquiring and Releasing a Lock

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

### Identifying the Condition Lock

- [name](foundation/nsconditionlock/name.md)

## Relationships

### Inherits From

- [NSObject](objectivec/nsobject-swift.class.md)

### Conforms To

- [CVarArg](swift/cvararg.md)
- [CustomDebugStringConvertible](swift/customdebugstringconvertible.md)
- [CustomStringConvertible](swift/customstringconvertible.md)
- [Equatable](swift/equatable.md)
- [Hashable](swift/hashable.md)
- [NSLocking](foundation/nslocking.md)
- [NSObjectProtocol](objectivec/nsobjectprotocol.md)
- [Sendable](swift/sendable.md)
- [SendableMetatype](swift/sendablemetatype.md)

## See Also

### Threads and Locking

- [Thread](foundation/thread.md)
- [NSLocking](foundation/nslocking.md)
- [NSLock](foundation/nslock.md)
- [NSRecursiveLock](foundation/nsrecursivelock.md)
- [NSDistributedLock](foundation/nsdistributedlock.md)
- [NSCondition](foundation/nscondition.md)
