<!--
{
  "availability" : [
    "macCatalyst: 13.0.0 -",
    "macOS: 10.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/NSDistributedLock/try()",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSDistributedLock(im)tryLock"
  },
  "title" : "try()"
}
-->

# try()

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

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

## Return Value

<doc://com.apple.documentation/documentation/Swift/true> if the attempt to acquire the receiver was successful, otherwise <doc://com.apple.documentation/documentation/Swift/false>.

## Discussion

Raises `NSGenericException` if a file-system error occurs.

## See Also

[`unlock()`](/documentation/Foundation/NSDistributedLock/unlock())

Relinquishes the receiver.



---

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)