<!--
{
  "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/readToEndOfFileInBackgroundAndNotify(forModes:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSFileHandle(im)readToEndOfFileInBackgroundAndNotifyForModes:"
  },
  "title" : "readToEndOfFileInBackgroundAndNotify(forModes:)"
}
-->

# readToEndOfFileInBackgroundAndNotify(forModes:)

Reads to the end of file from the file or communications channel in the background and posts a notification when finished.

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

## Parameters

`modes`

The runloop modes in which the read completion notification can be posted.

## Discussion

See [`readToEndOfFileInBackgroundAndNotify()`](/documentation/Foundation/FileHandle/readToEndOfFileInBackgroundAndNotify()) for details of this method’s operation. The method differs from [`readToEndOfFileInBackgroundAndNotify()`](/documentation/Foundation/FileHandle/readToEndOfFileInBackgroundAndNotify()) in that `modes` specifies the run-loop mode (or modes) in which [`NSFileHandleReadToEndOfFileCompletion`](/documentation/Foundation/NSNotification/Name-swift.struct/NSFileHandleReadToEndOfFileCompletion) can be posted.

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

## See Also

[`-  enqueueNotification:postingStyle:coalesceMask:forModes:`](/documentation/Foundation/NotificationQueue/enqueue(_:postingStyle:coalesceMask:forModes:))

Adds a notification to the notification queue with a specified posting style, criteria for coalescing, and run loop mode.



---

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)