<!--
{
  "availability" : [
    "iOS: 5.0.0 -",
    "iPadOS: 5.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.7.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/FileManager/setUbiquitous(_:itemAt:destinationURL:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSFileManager(im)setUbiquitous:itemAtURL:destinationURL:error:"
  },
  "title" : "setUbiquitous(_:itemAt:destinationURL:)"
}
-->

# setUbiquitous(_:itemAt:destinationURL:)

Indicates whether the item at the specified URL should be stored in iCloud.

```
func setUbiquitous(_ flag: Bool, itemAt url: URL, destinationURL: URL) throws
```

## Parameters

`flag`

<doc://com.apple.documentation/documentation/Swift/true> to move the item to iCloud or <doc://com.apple.documentation/documentation/Swift/false> to remove it from iCloud (if it is there currently).

`url`

The URL of the item (file or directory) that you want to store in iCloud.

`destinationURL`

When moving a file into iCloud, this is the location in iCloud at which to store the file or directory. This URL must be constructed from a URL returned by the [`url(forUbiquityContainerIdentifier:)`](/documentation/Foundation/FileManager/url(forUbiquityContainerIdentifier:)) method, which you use to retrieve the desired iCloud container directory. The URL you specify may contain additional subdirectories so that you can organize your files hierarchically in iCloud. However, you are responsible for creating those intermediate subdirectories (using the [`FileManager`](/documentation/Foundation/FileManager) class) in your iCloud container directory. When moving a file *out of iCloud*, this is the location on the local device.

## Discussion

Use this method to move a file from its current location to iCloud. For files located in an app’s sandbox, this involves physically removing the file from the sandbox container. (The system extends your app’s sandbox privileges to give it access to files it moves to iCloud.) You can also use this method to move files out of iCloud and back into a local directory.

If your app is presenting the file’s contents to the user, it must have an active file presenter object configured to monitor the specified file or directory before calling this method. When you specify <doc://com.apple.documentation/documentation/Swift/true> for the `flag` parameter, this method attempts to move the file or directory to the cloud and returns <doc://com.apple.documentation/documentation/Swift/true> if it is successful. Calling this method also notifies your file presenter of the new location of the file so that your app can continue to operate on it.

> Important:
> Avoid calling this method from your app’s main thread. This method performs a coordinated write operation on the specified file, which can block for a long time. Additionally, if the file presenter that is monitoring the file is incorrectly configured so that it receives messages on the main operation queue, calling this method on the main thread can cause a deadlock. Instead, use a dispatch queue to call this method from background thread. After the method returns, message your main thread to update the rest of your app’s data structures.
> 
> After calling this method, you must wait for a file to be fully uploaded to iCloud before attempting to share the file using the ``doc://com.apple.foundation/documentation/Foundation/FileManager/url(forPublishingUbiquitousItemAt:expiration:)`` method.

> Handling Errors in Swift:
> In Swift, this method returns `Void` 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](https://docs.swift.org/swift-book/LanguageGuide/ErrorHandling.html) in [The Swift Programming Language](https://docs.swift.org/swift-book/) and `About Imported Cocoa Error Parameters`.

---

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)