---
title: readToEndOfFileInBackgroundAndNotify()
framework: foundation
role: symbol
role_heading: Instance Method
path: foundation/filehandle/readtoendoffileinbackgroundandnotify()
---

# readToEndOfFileInBackgroundAndNotify()

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

## Declaration

```swift
func readToEndOfFileInBackgroundAndNotify()
```

## Discussion

Discussion This method performs an asynchronous readToEndOfFile operation on a file or communications channel and posts an 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. In communication via stream-type sockets, the receiver is often the object returned in the userInfo dictionary of NSFileHandleConnectionAccepted.

## See Also

### Related Documentation

- [enqueue(_:postingStyle:coalesceMask:forModes:)](foundation/notificationqueue/enqueue(_:postingstyle:coalescemask:formodes:).md)

### Reading asynchronously with notifications

- [acceptConnectionInBackgroundAndNotify()](foundation/filehandle/acceptconnectioninbackgroundandnotify().md)
- [acceptConnectionInBackgroundAndNotify(forModes:)](foundation/filehandle/acceptconnectioninbackgroundandnotify(formodes:).md)
- [readInBackgroundAndNotify()](foundation/filehandle/readinbackgroundandnotify().md)
- [readInBackgroundAndNotify(forModes:)](foundation/filehandle/readinbackgroundandnotify(formodes:).md)
- [readToEndOfFileInBackgroundAndNotify(forModes:)](foundation/filehandle/readtoendoffileinbackgroundandnotify(formodes:).md)
- [waitForDataInBackgroundAndNotify()](foundation/filehandle/waitfordatainbackgroundandnotify().md)
- [waitForDataInBackgroundAndNotify(forModes:)](foundation/filehandle/waitfordatainbackgroundandnotify(formodes:).md)
