---
title: try()
framework: foundation
role: symbol
role_heading: Instance Method
path: foundation/nslock/try()
---

# try()

Attempts to acquire a lock and immediately returns a Boolean value that indicates whether the attempt was successful.

## Declaration

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

## Return Value

Return Value true if the lock was acquired, otherwise false.

## See Also

### Acquiring a Lock

- [lock(before:)](foundation/nslock/lock(before:).md)
