---
title: "addSubscriber(forFileURL:withPublishingHandler:)"
framework: foundation
role: symbol
role_heading: Type Method
path: "foundation/progress/addsubscriber(forfileurl:withpublishinghandler:)"
---

# addSubscriber(forFileURL:withPublishingHandler:)

Registers a file URL to hear about the progress of a file operation.

## Declaration

```swift
class func addSubscriber(forFileURL url: URL, withPublishingHandler publishingHandler: @escaping Progress.PublishingHandler) -> Any
```

## Parameters

- `url`: The URL of the file to observe.
- `publishingHandler`: A closure that the system invokes when a progress object that represents a file operation matching the specified URL calls doc://com.apple.foundation/documentation/Foundation/Progress/publish().

## Return Value

Return Value A proxy of the progress object to observe.

## Discussion

Discussion The system invokes the passed-in block when a progress object calls publish() with a fileURLKey user info dictionary entry that’s a URL that is the same as this method’s URL, or that is an item that the URL directly contains. The progress object that passes to your block is a proxy of the published progress object. The passed-in block may return another block. If it does, the system invokes the returned block when the observed progress object invokes unpublish(), the publishing process terminates, or you invoke removeSubscriber(_:). The system invokes the blocks you provide on the main thread.

## See Also

### Observing and Controlling File Progress by Other Processes

- [removeSubscriber(_:)](foundation/progress/removesubscriber(_:).md)
- [isOld](foundation/progress/isold.md)
- [Progress.PublishingHandler](foundation/progress/publishinghandler.md)
- [Progress.UnpublishingHandler](foundation/progress/unpublishinghandler.md)
