<!--
{
  "availability" : [
    "iOS: -",
    "iPadOS: -",
    "macCatalyst: -",
    "macOS: -",
    "tvOS: -",
    "visionOS: -",
    "watchOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "ObjectiveC",
  "identifier" : "/documentation/ObjectiveC/NSObject-swift.class/attemptRecovery(fromError:optionIndex:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Objective-C Runtime",
      "ObjectiveC"
    ],
    "preciseIdentifier" : "c:objc(cs)NSObject(im)attemptRecoveryFromError:optionIndex:"
  },
  "title" : "attemptRecovery(fromError:optionIndex:)"
}
-->

# attemptRecovery(fromError:optionIndex:)

Implemented to attempt a recovery from an error noted in an application-modal dialog.

```
func attemptRecovery(fromError error: any Error, optionIndex recoveryOptionIndex: Int) -> Bool
```

## Parameters

`error`

An <doc://com.apple.documentation/documentation/Foundation/NSError> object that describes the error, including error recovery options.

`recoveryOptionIndex`

The index of the user selected recovery option in `error`’s localized recovery array.

## Return Value

[`YES`](/documentation/ObjectiveC/YES) if the error recovery was completed successfully, [`NO`](/documentation/ObjectiveC/NO) otherwise.

## Discussion

Invoked when an error alert is been presented to the user in an application-modal dialog, and the user has selected an error recovery option specified by `error`.

---

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)