Instance Method

setUbiquitous(_:itemAt:destinationURL:)

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

Declaration

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

Parameters

flag

true to move the item to iCloud or 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

Moving a file into iCloud 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:) 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 class) in your iCloud container directory.

Moving a file out of iCloud The location on the local device.

Return Value

true if the item’s status was updated successfully or false if an error occurred. If this method returns false and you specified a value for the errorOut parameter, this method returns an error object in the provided pointer.

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 true for the flag parameter, this method attempts to move the file or directory to the cloud and returns 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.

See Also

Managing iCloud-Based Items

var ubiquityIdentityToken: (NSCoding & NSCopying & NSObjectProtocol)?

An opaque token that represents the current user’s iCloud Drive Documents identity.

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

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

func isUbiquitousItem(at: URL) -> Bool

Returns a Boolean indicating whether the item is targeted for storage in iCloud.

func startDownloadingUbiquitousItem(at: URL)

Starts downloading (if necessary) the specified item to the local system.

func evictUbiquitousItem(at: URL)

Removes the local copy of the specified item that’s stored in iCloud.

func url(forPublishingUbiquitousItemAt: URL, expiration: AutoreleasingUnsafeMutablePointer<NSDate?>?) -> URL

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