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

# attemptRecovery(fromError:optionIndex:delegate:didRecoverSelector:contextInfo:)

Implemented to attempt a recovery from an error noted in a document-modal sheet.

```
func attemptRecovery(fromError error: any Error, optionIndex recoveryOptionIndex: Int, delegate: Any?, didRecoverSelector: Selector?, contextInfo: UnsafeMutableRawPointer?)
```

## 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.

`delegate`

An object that is the modal delegate.

`didRecoverSelector`

A selector identifying the method implemented by the modal delegate.

`contextInfo`

Arbitrary data associated with the attempt at error recovery, to be passed to `delegate` in `didRecoverSelector`.

## Discussion

Invoked when an error alert is presented to the user in a document-modal sheet, and the user has selected an error recovery option specified by `error`. After recovery is attempted, your implementation should send `delegate` the message specified in `didRecoverSelector`, passing the provided `contextInfo`.

The `didRecoverSelector` should have the following signature:

```objc
- (void)didPresentErrorWithRecovery:(BOOL)didRecover contextInfo:(void *)contextInfo;
```

where `didRecover` is [`YES`](/documentation/ObjectiveC/YES) if the error recovery attempt was successful; otherwise it is [`NO`](/documentation/ObjectiveC/NO).

---

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)