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

# url(forUbiquityContainerIdentifier:)

Returns the URL for the iCloud container associated with the specified identifier and establishes access to that container.

```
func url(forUbiquityContainerIdentifier containerIdentifier: String?) -> URL?
```

## Parameters

`containerIdentifier`

The fully-qualified container identifier for an iCloud container directory. The string you specify must not contain wildcards and must be of the form *<TEAMID>*`.`*<CONTAINER>*, where *<TEAMID>* is your development team ID and *<CONTAINER>* is the bundle identifier of the container you want to access.

    The container identifiers for your app must be declared in the     `com.apple.developer.ubiquity-container-identifiers`     array of the     `.entitlements`     property list file in your Xcode project.

    If you specify     `nil`     for this parameter, this method returns the first container listed in the     `com.apple.developer.ubiquity-container-identifiers`     entitlement array.

## Return Value

A URL pointing to the specified ubiquity container, or `nil` if the container could not be located or if iCloud storage is unavailable for the current user or device.

## Discussion

You use this method to determine the location of your app’s ubiquity container directories and to configure your app’s initial iCloud access. The first time you call this method for a given ubiquity container, the system extends your app’s sandbox to include that container. In iOS, you must call this method at least once before trying to search for cloud-based files in the ubiquity container. If your app accesses multiple ubiquity containers, call this method once for each container. In macOS, you do not need to call this method if you use <doc://com.apple.documentation/documentation/AppKit/NSDocument>-based objects, because the system then calls this method automatically.

You can use the URL returned by this method to build paths to files and directories within your app’s ubiquity container. Each app that syncs documents to the cloud must have at least one associated ubiquity container in which to put those files. This container can be unique to the app or shared by multiple apps.

> Important:
> Do not call this method from your app’s main thread. Because this method might take a nontrivial amount of time to set up iCloud and return the requested URL, you should always call it from a secondary thread. To determine if iCloud is available, especially at launch time, check the value of the ``doc://com.apple.foundation/documentation/Foundation/FileManager/ubiquityIdentityToken`` property instead.

In addition to writing to its own ubiquity container, an app can write to any container directory for which it has the appropriate permission. Each additional ubiquity container should be listed as an additional value in the `com.apple.developer.ubiquity-container-identifiers` entitlement array.

To learn how to view your development team’s unique *<TEAM_ID>* value, read To view the team ID in Tools Workflow Guide for Mac.

> Note:
> The development team ID that precedes each container ID string is the unique identifier associated with your development team. To learn how to view your development team’s unique *<TEAM_ID>* value, read To view the team ID in Tools Workflow Guide for Mac.

---

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)