---
title: "url(forPublishingUbiquitousItemAt:expiration:)"
framework: foundation
role: symbol
role_heading: Instance Method
path: "foundation/filemanager/url(forpublishingubiquitousitemat:expiration:)"
---

# url(forPublishingUbiquitousItemAt:expiration:)

Returns a URL that can be emailed to users to allow them to download a copy of a flat file item from iCloud.

## Declaration

```swift
func url(forPublishingUbiquitousItemAt url: URL, expiration outDate: AutoreleasingUnsafeMutablePointer<NSDate?>?) throws -> URL
```

## Parameters

- `url`: The URL of the item in the cloud that you want to share. The URL must be prefixed with the base URL returned from the doc://com.apple.foundation/documentation/Foundation/FileManager/url(forUbiquityContainerIdentifier:) method that corresponds to the item’s location. The file must be a flat file, not a bundle. The file at the specified URL must already be uploaded to iCloud when you call this method.
- `outDate`: On input, a pointer to a variable for a date object. On output, this parameter contains the date after which the item is no longer available at the returned URL. You may specify nil for this parameter if you are not interested in the date.

## Return Value

Return Value A URL with which users can download a copy of the item at url. In Objective-C, returns nil if the URL could not be created for any reason.

## Discussion

Discussion This method creates a snapshot of the specified flat file and places that copy in a temporary iCloud location where it can be accessed by other users using the returned URL. The snapshot reflects the contents of the file at the time the URL was generated and is not updated when subsequent changes are made to the original file in the user’s iCloud storage. The snapshot file remains available at the specified URL until the date specified in the outDate parameter, after which it is automatically deleted. Explicitly deleting the item by calling the removeItem(at:) or removeItem(atPath:) method also deletes all old versions of the item, invalidating URLs to those versions returned by this method. Your app must have access to the network for this call to succeed. If the specified file is in the process of being uploaded to iCloud, you must not call this method until the upload has finished. important: As of iOS 8.0 and macOS 10.10 The url must specify a flat file, not a bundle. Bundles have a folder as the root item. note: In Swift, this method returns a nonoptional result and is marked with the throws keyword to indicate that it throws an error in cases of failure. You call this method in a try expression and handle any errors in the catch clauses of a do statement, as described in Error Handling in The Swift Programming Language and About Imported Cocoa Error Parameters.

## See Also

### Managing iCloud-based items

- [ubiquityIdentityToken](foundation/filemanager/ubiquityidentitytoken.md)
- [url(forUbiquityContainerIdentifier:)](foundation/filemanager/url(forubiquitycontaineridentifier:).md)
- [isUbiquitousItem(at:)](foundation/filemanager/isubiquitousitem(at:).md)
- [setUbiquitous(_:itemAt:destinationURL:)](foundation/filemanager/setubiquitous(_:itemat:destinationurl:).md)
- [startDownloadingUbiquitousItem(at:)](foundation/filemanager/startdownloadingubiquitousitem(at:).md)
- [evictUbiquitousItem(at:)](foundation/filemanager/evictubiquitousitem(at:).md)
