---
title: PHCloudIdentifier
framework: photos
role: symbol
role_heading: Class
path: photos/phcloudidentifier
---

# PHCloudIdentifier

An object that identifies an asset or collection that syncs through iCloud Photos.

## Declaration

```swift
class PHCloudIdentifier
```

## Overview

Overview A cloud identifier is a type of identifier that behaves like a local identifier. Use cloud identifiers to identify objects that sync across devices through iCloud Photos. You can store, sync, and use cloud identifiers with devices synced with an iCloud account. You’re also able to use secure coding to encode and decode cloud identifiers. A local identifier is valid for referring to objects only in the context of a local device. These objects include PHAsset, PHAssetCollection, and PHCollectionList. Because a cloud identifier is universal, you can use it on any iCloud-synced device. Convert the cloud identifier back to a local identifier and perform a fetch to find the equivalent object on that device. Perform batch lookups of identifiers using localIdentifierMappingsForCloudIdentifiers: and cloudIdentifierMappingsForLocalIdentifiers:. // Get the local identifier mappings for the cloud identifiers. let identifierMappings = library.localIdentifierMappings(for: assetCloudIdentifiers) Retrieving identifier mappings can be an expensive operation, so perform lookups sparingly. If a lookup fails, inspect the error property on PHCloudIdentifierMapping or PHLocalIdentifierMapping for details. See PHPhotosError.Code for additional error details. // Iterate over the cloud identifiers and add or handle missing local identifiers. for cloudIdentifier in assetCloudIdentifiers {     guard let identifierMapping = identifierMappings[cloudIdentifier] else {         print("Failed to find a mapping for \(cloudIdentifier).")         continue     }

// Track the local identifier if it exists.     if let localIdentifier = identifierMapping.localIdentifier {         localIdentifiers.append(localIdentifier)     } else if let error = identifierMapping.error as? PHPhotosError {         switch error.code {         case .identifierNotFound:             // Skip the missing or deleted assets.             print("Failed to find the local identifier for \(cloudIdentifier). \(error.localizedDescription))")         case .multipleIdentifiersFound:             // Prompt the user to resolve the cloud identifier that matched multiple assets.             print("Found multiple local identifiers for \(cloudIdentifier). \(error.localizedDescription)")             if let selectedLocalIdentifier = promptUserForPotentialReplacement(with: error.userInfo[PHLocalIdentifiersErrorKey]) {                 localIdentifiers.append(selectedLocalIdentifier)             }         default:             print("Encountered an unexpected error looking up the local identifier for \(cloudIdentifier). \(error.localizedDescription)")         }     } }

// Fetch assets using the found identifiers. let mappedAssets = PHAsset.fetchAssets(withLocalIdentifiers: localIdentifiers,                                         options: nil)

## Topics

### Using Cloud Identifiers

- [init(stringValue:)](photos/phcloudidentifier/init(stringvalue:).md)
- [stringValue](photos/phcloudidentifier/stringvalue.md)
- [notFound](photos/phcloudidentifier/notfound.md)

### Initializers

- [init(archivalStringValue:)](photos/phcloudidentifier/init(archivalstringvalue:).md)
- [init(coder:)](photos/phcloudidentifier/init(coder:).md)

### Instance Properties

- [archivalStringValue](photos/phcloudidentifier/archivalstringvalue.md)

## Relationships

### Inherits From

- [NSObject](objectivec/nsobject-swift.class.md)

### Conforms To

- [CVarArg](swift/cvararg.md)
- [Copyable](swift/copyable.md)
- [CustomDebugStringConvertible](swift/customdebugstringconvertible.md)
- [CustomStringConvertible](swift/customstringconvertible.md)
- [Equatable](swift/equatable.md)
- [Escapable](swift/escapable.md)
- [Hashable](swift/hashable.md)
- [NSCoding](foundation/nscoding.md)
- [NSCopying](foundation/nscopying.md)
- [NSObjectProtocol](objectivec/nsobjectprotocol.md)
- [NSSecureCoding](foundation/nssecurecoding.md)
- [Sendable](swift/sendable.md)
- [SendableMetatype](swift/sendablemetatype.md)

## See Also

### Converting Between Local and iCloud Identifiers

- [cloudIdentifierMappings(forLocalIdentifiers:)](photos/phphotolibrary/cloudidentifiermappings(forlocalidentifiers:).md)
- [localIdentifierMappings(for:)](photos/phphotolibrary/localidentifiermappings(for:).md)
- [cloudIdentifiers(forLocalIdentifiers:)](photos/phphotolibrary/cloudidentifiers(forlocalidentifiers:).md)
- [localIdentifiers(for:)](photos/phphotolibrary/localidentifiers(for:).md)
- [PHLocalIdentifierNotFound](photos/phlocalidentifiernotfound.md)
