---
title: NSLocking
framework: foundation
role: symbol
role_heading: Protocol
path: foundation/nslocking
---

# NSLocking

The elementary methods adopted by classes that define lock objects.

## Declaration

```swift
protocol NSLocking
```

## Overview

Overview A lock object is used to coordinate the actions of multiple threads of execution within a single application. By using a lock object, an application can protect critical sections of code from being executed simultaneously by separate threads, thus protecting shared data and other shared resources from corruption.

## Topics

### Working with Locks

- [lock()](foundation/nslocking/lock().md)
- [unlock()](foundation/nslocking/unlock().md)

### Instance Methods

- [withLock(_:)](foundation/nslocking/withlock(_:).md)

## Relationships

### Conforming Types

- [NSCondition](foundation/nscondition.md)
- [NSConditionLock](foundation/nsconditionlock.md)
- [NSLock](foundation/nslock.md)
- [NSRecursiveLock](foundation/nsrecursivelock.md)

## See Also

### Threads and Locking

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