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

# readToEndOfFileInBackgroundAndNotify()

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

```
func readToEndOfFileInBackgroundAndNotify()
```

## Discussion

This method performs an asynchronous `readToEndOfFile` operation on a file or communications channel and posts an [`NSFileHandleReadToEndOfFileCompletion`](/documentation/Foundation/NSNotification/Name-swift.struct/NSFileHandleReadToEndOfFileCompletion). You must call this method from a thread that has an active run loop.

The notification includes a `userInfo` dictionary that contains the data read; access this object using the `NSFileHandleNotificationDataItem` key.

Any object interested in receiving this data asynchronously must add itself as an observer of [`NSFileHandleReadToEndOfFileCompletion`](/documentation/Foundation/NSNotification/Name-swift.struct/NSFileHandleReadToEndOfFileCompletion). In communication via stream-type sockets, the receiver is often the object returned in the `userInfo` dictionary of [`NSFileHandleConnectionAccepted`](/documentation/Foundation/NSNotification/Name-swift.struct/NSFileHandleConnectionAccepted).

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