<!--
{
  "availability" : [
    "iOS: 2.0.0 -",
    "iPadOS: 2.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.0.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/FileHandle/waitForDataInBackgroundAndNotify(forModes:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSFileHandle(im)waitForDataInBackgroundAndNotifyForModes:"
  },
  "title" : "waitForDataInBackgroundAndNotify(forModes:)"
}
-->

# waitForDataInBackgroundAndNotify(forModes:)

Asynchronously checks to see if data is available.

```
func waitForDataInBackgroundAndNotify(forModes modes: [RunLoop.Mode]?)
```

## Parameters

`modes`

The runloop modes in which the data available notification can be posted.

## Discussion

When the data becomes available, this method posts a [`NSFileHandleDataAvailable`](/documentation/Foundation/NSNotification/Name-swift.struct/NSFileHandleDataAvailable) notification on the current thread. This method differs from [`waitForDataInBackgroundAndNotify()`](/documentation/Foundation/FileHandle/waitForDataInBackgroundAndNotify()) in that `modes` specifies the run-loop mode (or modes) in which [`NSFileHandleDataAvailable`](/documentation/Foundation/NSNotification/Name-swift.struct/NSFileHandleDataAvailable) can be posted.

You must call this method from a thread that has an active run loop.

---

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)