---
title: lockIfAvailable()
framework: os
role: symbol
role_heading: Instance Method
path: os/osallocatedunfairlock/lockifavailable()
---

# lockIfAvailable()

Attempts to acquire a lock.

## Declaration

```swift
func lockIfAvailable() -> Bool
```

## Return Value

Return Value true if successful; otherwise, false.

## See Also

### Using locks

- [lock()](os/osallocatedunfairlock/lock().md)
- [unlock()](os/osallocatedunfairlock/unlock().md)
